Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to find a Particular grid column to click on checkbox????


foreach (GridViewRow grow in gdvheader.Rows)
{

CheckBox chknav = (CheckBox)grow.FindControl("chksyncnav");

if (chknav.Checked)
{
int id = Convert.ToInt32(grow.Cells[1].Text);

}
}

What I have tried:

foreach (GridViewRow grow in gdvheader.Rows)
        {
            
           CheckBox chknav = (CheckBox)grow.FindControl("chksyncnav");
            
           if (chknav.Checked)
           {
               int id = Convert.ToInt32(grow.Cells[1].Text);
                
           }
        }
Posted
Updated 19-Nov-18 8:22am
Comments
alexvw 19-Nov-18 8:14am    
Hi Rajesh,

Could you rephrase your question; what is it what you are trying to accomplish? What is it not working as expected? is there an error message?

Just copying a portion of code in both the question and in the "What I have tried" sections is not enough for others to understand and help.

Cheers!

1 solution

You question is too unclear and I'm not entirely sure if I follow you correctly. If you are trying to access a Column value when a CheckBox is checked then you can do something like this:

ASPX:
ASP.NET
<asp:TemplateField>
    <HeaderTemplate>
      <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
    </HeaderTemplate>
</asp:TemplateField>


You can then cast the sender to get reference to the CheckBox at CheckedChanged event like:

C#
protected void CheckBox1_CheckedChanged(object sender, EventArgs e){
        CheckBox cb = (CheckBox)sender;
        if (cb.Checked){
            GridViewRow row = (GridViewRow)cb.NamingContainer;
	    //access whatever controls here
        }
        else {
            //do something else
        }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900