Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get a check box id in a grid view...
I am getting the out put of the checked checkbox as false..
I have tried this:
C#
int k = 0;
//Checkther whether atleast one check box is selected or not
for (int i = 0; i <= GridViewExample.Rows.Count - 1; i++)
{
       GridViewRow row = GridViewExample.Rows[i];
       CheckBox Ckbox = (CheckBox)row.FindControl("cbkCheck");
       //bool Ckbox = ((CheckBox)row.FindControl("cbkCheck")).Checked;
       if (Ckbox.Checked == true)
       //if (Ckbox)
       {
            k++;
       }
}
Posted
v3
Comments
VishwaKL 17-Dec-12 5:26am    
have written autopostback=true for checkbox control?
Suresh Dasari's 17-Dec-12 6:27am    
May be your binding the GridView again before the execution of this code.
if it is the case then comment these lines before the execution of this code.
//GridView1.DataSource = your datasource;
//GridView1.DataBind();
In which event you are trying to get the CheckBox?
ZurdoDev 17-Dec-12 8:22am    
Need more details. If you are binding in page_load and not checking for IsPostBack this is a common mistake.
AshishChaudha 18-Dec-12 2:11am    
Please elaborate your question for better help.

1 solution

Hi,

try this

foreach(Gridviewrow gvr in Gridview1.Rows)
{
if(((CheckBox)gvr.findcontrol("CheckBox1")).Checked == true)
{


}
}
 
Share this answer
 

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