Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count;i++ )
        {
            CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
        }
    }



I am not able to get selected checkbox's values......if it checkbox is checked means it has delete that particular row after clicking on a delete button...


Anybody please help

PLease checkout snapshots below..
image1
link2
Posted
Updated 6-Dec-12 22:29pm
v4
Comments
[no name] 7-Dec-12 3:36am    
Why did you post it again ??
AnkitGoel.com 7-Dec-12 3:45am    
Have u tried by creating InsertItemTemplate and EditItemTemplate ?
pradiprenushe 7-Dec-12 4:34am    
Where you are binding gridview? Is it in Page_Load event?

foreach(GridViewRow row in GridView1.Rows)
{
    CheckBox chk = (CheckBox)row.FindControl("CheckBox1");
    if(chk.Checked)
    {
         // code here
    }
}
 
Share this answer
 
Why are you using "as" keyword when you are already casting your control as checkbox?

Try:
CheckBox chk = new CheckBox;
chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");

instead of:
CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1") as CheckBox;
 
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