Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 6-Dec-12 21:33pm
Edited 6-Dec-12 22:29pm
v4
Comments
Krunal Rohit at 7-Dec-12 3:36am
   
Why did you post it again ??
AnkitGoel.com at 7-Dec-12 3:45am
   
Have u tried by creating InsertItemTemplate and EditItemTemplate ?
pradiprenushe at 7-Dec-12 4:34am
   
Where you are binding gridview? Is it in Page_Load event?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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;
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

foreach(GridViewRow row in GridView1.Rows)
{
    CheckBox chk = (CheckBox)row.FindControl("CheckBox1");
    if(chk.Checked)
    {
         // code here
    }
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 883
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 166
4 ChauhanAjay 150
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100