Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have Datagrid in asp.net page with the below mentioned data
Device_Name | Column1 | Column2
---------------------------------------
iPad | CHECK BOX | CHECK BOX
iPhone | CHECK BOX | CHECK BOX

here Device_Name,Column1 and Column2 are column names, under these columns we have check boxes on both the columns, Please can any body help me how do I we get to know which all the check box's are TICKED/MARKED.

We should be able to tick any check box at any time

Could you please some one help me one this

[EDIT - OP comment from "solution" before it is deleted]
Thanks Nirav and Raje for your quick response, However your code is not working.

Here is my Code to auto generate my Gridview
===============================================
C#
protected void GrdOSInfo_RowDataBound(object sender, GridViewRowEventArgs e)
       {
        if (e.Row.RowType == DataControlRowType.DataRow)
           {
               for (int i = 1; i < 3; i++)
               {
                   //foreach (GridView row in GridView1.Rows)
                   //{
                   CheckBox chk = new CheckBox();
                   chk.EnableViewState = true;
                   chk.Enabled = true;
                   chk.ID = "chkb"+i;

                   e.Row.Cells[i].Controls.Add(chk);
                   //}
               }
           }
       }

================================================

So here basically I want to know how do I assign checked value (just to identify which are been ticked) to array list from Grid view (for storing purpose, later I will pass this arraylist to next page).

Can any one please help me on this, I will be really great full to your help
Posted
Updated 2-Aug-14 4:35am
v2

Using ASP.Net :
C#
int EmpId = 0;
foreach(Gridviewrow gvr in Gridview1.Rows)
{
 if(((CheckBox)gvr.findcontrol("chkId")).Checked == true)
 {
    EmpId = Convert.ToInt32(gvr.cells["EmployeeId"]);
 }
}


Good luck
 
Share this answer
 
v2
Comments
CHill60 2-Aug-14 10:39am    
OP has tried to respond - I've put his comments into the original quesitons
try this.. :)

C#
foreach(GridViewRow gvrow in gvGrid.Rows)
{
CheckBox chk1 = (CheckBox)gvrow.FindControl("chkSelect1"); //Find control of checkbox1
CheckBox chk2 = (CheckBox)gvrow.FindControl("chkSelect2"); //Find control of checkbox22
if (chk1 != null & chk1.Checked)
{
  //do stuff when checked
}
else
{
//do stuff when UnChecked
}

if (chk2 != null & chk2.Checked)
{
  //do stuff when checked
}
else
{
//do stuff when UnChecked
}
}
 
Share this answer
 
v2
Comments
CHill60 2-Aug-14 10:40am    
OP has tried to respond - I've put his comments into the original question
Thanks Nirav and Raje for your quick response, However your code is not working.

Here is my Code to auto generate my Gridview
===============================================
C#
protected void GrdOSInfo_RowDataBound(object sender, GridViewRowEventArgs e)
       {
        if (e.Row.RowType == DataControlRowType.DataRow)
           {
               for (int i = 1; i < 3; i++)
               {
                   //foreach (GridView row in GridView1.Rows)
                   //{
                   CheckBox chk = new CheckBox();
                   chk.EnableViewState = true;
                   chk.Enabled = true;
                   chk.ID = "chkb"+i;

                   e.Row.Cells[i].Controls.Add(chk);
                   //}
               }
           }
       }

================================================

So here basically I want to know how do I assign checked value (just to identify which are been ticked) to array list from Grid view (for storing purpose, later I will pass this arraylist to next page).


Can any one please help me on this, I will be really great full to your help
 
Share this answer
 
Comments
CHill60 2-Aug-14 10:34am    
Nirav and Raje will not know that you are trying to respond because you did not Reply to their posts. Use the Improve Question link to add extra information to your question and the Reply link next to a post to respond - the poster will be notified that you have responded
shankar01021981 3-Aug-14 0:18am    
Can any one please help me on my problem , its still not resolved

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