Reputation: 347
I am unable to get row values in Grid by checking check box. selected check box is always getting false in code behind. Please help me to solve this problem. Thanks in advance
This is my aspx code:
<asp:GridView ID="resumeSearchGrid" DataKeyNames="CandidateID" CellPadding="5" runat="server" Width="100%" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CandidateID" HeaderText="CandidateID" Visible="false" />
<asp:BoundField DataField="CandidateName" HeaderText="Name" />
<asp:BoundField DataField="EmailID" HeaderText=" Email Id" />
</Columns>
</asp:GridView>
<asp:Button ID="Button1" class="button" runat="server"
Text="Send to client" onclick="Button1_Click"></asp:Button>
This is my code behind :
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in resumeSearchGrid.Rows)
{
CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
if (chk != null && chk.Checked)
{
Name += resumeSearchGrid.DataKeys[gvrow.RowIndex].Value.ToString() + ',';
eMail += gvrow.Cells[2].Text + ',';
}
}
}
Upvotes: 2
Views: 22303
Reputation: 1072
You write chkSelectlist
instead of chkSelect
in FindControl
CheckBox chk = (CheckBox)gvrow.FindControl("chkSelectlist");
And if condition only write
if (chk.Checked)
{
}
Upvotes: 2