0
我想使用javascript在gridview中獲取文本框的值。但我無法找到價值。這是我的Asp.net頁面。如何從更新按鈕onclientclick獲取「txtGridName」值?如何使用javascript在gridview中獲取文本框的值
Asp.net代碼在這裏:
<Columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate> <%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Std">
<EditItemTemplate>
<%--<asp:TextBox ID="txtLocEditName" Width="100%" runat="server" Text='<%#(Eval("loc_name").ToString()) %>' />--%>
<asp:DropDownList ID="drpGridUnitStd" runat="server" Text='<%#(Eval("uom_standard").ToString()) %>'>
<asp:ListItem Text="A" Value="A"></asp:ListItem>
<asp:ListItem Text="I" Value="I"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblLocation" runat="server" Text='<%#(Eval("uom_standard").ToString())%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Name">
<EditItemTemplate>
<asp:TextBox ID="txtGridName" Width="100%" runat="server" Text='<%#(Eval("uom_ts_unit").ToString()) %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGridName" runat="server" Text='<%#(Eval("uom_ts_unit").ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dimension-1">
<EditItemTemplate>
<asp:TextBox ID="txtGridDim1" Width="100%" runat="server" Text='<%#(Eval("uom_dimension_1").ToString()) %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGridDim1" runat="server" Text='<%#(Eval("uom_dimension_1").ToString())%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dimension-2">
<EditItemTemplate>
<asp:TextBox ID="txtGridDim2" Width="100%" runat="server" Text='<%#(Eval("uom_dimension_2").ToString()) %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGridDim2" runat="server" Text='<%#(Eval("uom_dimension_2").ToString())%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dimension-3">
<EditItemTemplate>
<asp:TextBox ID="txtGridDim3" Width="100%" runat="server" Text='<%#(Eval("uom_dimension_3").ToString()) %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGridDim3" runat="server" Text='<%#(Eval("uom_dimension_3").ToString())%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dimension-4">
<EditItemTemplate>
<asp:TextBox ID="txtGridDim4" Width="100%" runat="server" Text='<%#(Eval("uom_dimension_4").ToString()) %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblGridDim4" runat="server" Text='<%#(Eval("uom_dimension_4").ToString())%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-CssClass="hideGridColumn" ItemStyle-CssClass="hideGridColumn">
<ItemTemplate>
<asp:HiddenField ID="hdnUnit_Id" Value='<%#(Eval("unit_id").ToString())%>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Options">
<EditItemTemplate>
<asp:ImageButton ID="imgbtnUpdate" CommandName="Update" runat="server" ImageUrl="~/common/icons/Save-icon.png" ToolTip="Update" Height="15px" Width="15px" OnClientClick="return update();"/>
<asp:ImageButton ID="imgbtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/common/icons/Delete-icon.png" ToolTip="Cancel" Height="15px" Width="15px" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton ID="imgbtnEdit" CommandName="Edit" runat="server" ImageUrl="~/common/icons/edit.png" ToolTip="Edit" Height="15px" Width="15px" />
<asp:ImageButton ID="imgbtnDelete" CommandName="Delete" runat="server" ImageUrl="~/common/icons/delete.png" ToolTip="Delete" Height="15px" Width="15px" OnClientClick="return del();" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Javascript代碼如下:
function update()
{
var grid1 = document.getElementById("<%= gvUnit.ClientID %>");
for (i = 1; i < grid1.rows.length ; i++)
{
var cellValue = grid1.rows[i].cells[1].value;
alert(cellValue);
}
}