I am facing this situation and have no idea how to solve it. I have Gridview with this columns and this sample values:
CHECKBOX NAME SURNAME
-------------------------
Checkbox1 John Smith
Checkbox2 Jerry Rose
Checkobx3 Will Mathews
I have a problem to get value from second column from dynamically created gridview where checkbox is checked. So I check Checkbox2 and now I want to get value from Name column for this row. In this case that would be "Jerry".
Also, if I checked Checkbox1 and Checkbox2 I want to get "John" and "Jerry" split by comma.
My code so far:
$('#<%=GridView1.ClientID %> tbody >tr >td >input:checked').each(function () {
alert($(this).find("td").eq(2).html());
var values+=$(this).find("td").eq(2).html()+","; //values splitted by comma
});
Below is my gridview code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader"
onclick="javascript:SelectAllCheckboxes1(this);" runat="server" />
</HeaderTemplate>
</asp:TemplateField>
When I run this code results are just "undefined". What is wrong?
Please help me out.