Click here to Skip to main content
12,690,575 members (33,833 online)
Rate this:
 
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 17-Dec-12 5:26am
   
have written autopostback=true for checkbox control?
SureshDasari1986 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 17-Dec-12 6:56am
   
In which event you are trying to get the CheckBox?
ryanb31 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.
ashokmmrk 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
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