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 22:33pm
Edited 6-Dec-12 23: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 2

foreach(GridViewRow row in GridView1.Rows)
{
    CheckBox chk = (CheckBox)row.FindControl("CheckBox1");
    if(chk.Checked)
    {
         // code here
    }
}
  Permalink  
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  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 205
3 Jochen Arndt 180
4 Sergey Alexandrovich Kryukov 165
0 OriginalGriff 5,130
1 DamithSL 4,157
2 Maciej Los 3,650
3 Kornfeld Eliyahu Peter 3,460
4 Sergey Alexandrovich Kryukov 2,811


Advertise | Privacy | Mobile
Web01 | 2.8.141216.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