[英]To get row id using javascript
In the below code ia have a grid view and i want to get the product id using the javascript on clicking apply button.I tried the below code i couldn't able to get product ID .Please help me to do this. 在下面的代码中,我有一个网格视图,我想在单击应用按钮时使用JavaScript获取产品ID。我尝试了下面的代码,我无法获得产品ID。请帮助我做到这一点。
function getIndex(index) {
alert(index);
var grid = document.getElementById('<%=gdsalespricetrigger.ClientID %>');
alert(grid);
var cell = grid.rows[(+index) + 1].cells[0];
alert(cell.innerHTML);
var item = 'MainContent_gdsalespricetrigger_lblproductid_' + index.toString();
alert(item);
var grid1 = document.getElementById(item).value;
alert(grid1);
}
<asp:GridView Width="100%" runat="server" ID="gdsalespricetrigger" AutoGenerateColumns="false" DataKeyNames="ProductID" CellPadding="4" ForeColor="#333333" ShowFooter="true"
PageSize-Mode="NumericPages" OnRowDataBound="gdsalespricetrigger_RowDataBound" PageSize="10" PagerStyle-Visible="true" AllowPaging="true" AllowSorting="true"
CssClass="mGrid"
PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt">
<Columns>
<asp:TemplateField HeaderText="Product ID" ItemStyle-Width="350px" Visible="false">
<ItemTemplate>
<asp:Label ID="lblproductid" Text='<%#Eval("ProductID") %>' runat="server" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Name" ItemStyle-Width="350px" >
<ItemTemplate>
<asp:Label ID="lblproductname" Text='<%#Eval("ProductName") %>' runat="server" ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Apply" ItemStyle-Width="50px" >
<ItemTemplate>
<input type="button" value="Apply" onclick="getIndex(<%# Container.DataItemIndex %>);" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle Font-Bold="True" ForeColor="White" />
<FooterStyle HorizontalAlign="Right" />
</asp:GridView>
由于您使用的是Visible="false"
,因此控件本身不会被呈现,因此您无法使用Javascript操作它,而是需要使用:-
display:none;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.