I am trying to get the entire datagrid row on checkbox selection .
but I can get only the value of id which is bound to checkbox but not others. My code is below:
function btnClick() {
var mytext
var gridView1Control = document.getElementById('<%= indivPrincipalGrid.ClientID %>');
$('#<%= btnGetData.ClientID %>').click(function(e) {
$('input:checkbox[id$=CheckSelect]:checked', gridView1Control).each(function(item, index) {
var id = $(this).next('input:hidden[id$=hdID]').val();
var nm = $(this).find('input:hidden[id$=hdID1]').val();
alert(id);
alert(nm);
});
return false;
});
my grid is as follows :
<div>
<asp:Label ID="Label1" runat="server" Text="test"Font-Bold = "true"></asp:Label>
<asp:GridView ID="indivPrincipalGrid" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField = "Name"/>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckSelect" runat="server" />
<asp:HiddenField ID="hdID" runat="server" Value='<%# Eval("ID")%>'/>
<asp:HiddenField ID="hdID1" runat="server" Value='<%# Eval("Name")%>'/>
</ItemTemplate></asp:TemplateField></Columns></asp:GridView>
<asp:Button ID="btnGetData" runat="server" Text="Button" OnClientClick = "btnClick()" />
</div>
OK..
I found that the function supposed to populate the hidden cntrl wasn’t working ok and hence i was getting undefined in client script. Fixing it resolved the issue. Thanks all for help.