2

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 + ',';
        }
    }
}
6
  • are you getting chk as null or are you getting its checked as false? Commented Aug 6, 2014 at 6:53
  • do you have any update panel on your page? sometimes they are known to cause such problems Commented Aug 6, 2014 at 7:09
  • Initially i checked without update panel,after then checked with update panel. In both situation its not working. Still i am getting false. Commented Aug 6, 2014 at 7:11
  • seems weird!! try creating another grid in your page and only place a check box in it and see if you are able to get its checked values. Commented Aug 6, 2014 at 7:13
  • have you put trigger of submit button in your content panal for checkbox list? Commented Aug 6, 2014 at 7:32

1 Answer 1

2

You write chkSelectlist instead of chkSelect in FindControl

CheckBox chk = (CheckBox)gvrow.FindControl("chkSelectlist");

And if condition only write

if (chk.Checked)
{

}
Sign up to request clarification or add additional context in comments.

3 Comments

I tried it. But still i am getting false in That condition. I don't know why its not working. I created one sample application, there it's working fine. But in my application only its not working
@user3336505 in page load event your grid bind inside if (!IsPostBack) or Not ?
OMG..No. I didn't use (!IsPostBack). i added now. Its working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.