Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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:
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 16-Dec-12 23:15pm
v3
Comments
VishwaKL at 17-Dec-12 5:26am
   
have written autopostback=true for checkbox control?
SureshDasari1986 at 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();
Tadit Dash at 17-Dec-12 6:56am
   
In which event you are trying to get the CheckBox?
ryanb31 at 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 at 18-Dec-12 2:11am
   
Please elaborate your question for better help.
ashokmmrk at 18-Dec-12 4:49am
   
Do you want to get checkebox id which was checked

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

}
}
  Permalink  

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

  Print Answers RSS
0 CHill60 210
1 Sergey Alexandrovich Kryukov 200
2 Peter Leow 170
3 Richard Deeming 166
4 Zoltán Zörgő 135
0 Sergey Alexandrovich Kryukov 9,248
1 OriginalGriff 6,806
2 Peter Leow 4,432
3 Zoltán Zörgő 3,919
4 Richard MacCutchan 2,782


Advertise | Privacy | Mobile
Web01 | 2.8.150129.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2015
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