Click here to Skip to main content
12,697,103 members (26,420 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
Hello All..
I have a Gridview with some fields and a Check box.I need to retrieve the selected check box values which are stored in database into the gridview.

Any Suggestions..?
Posted 24-Sep-12 19:48pm
cunny301
Updated 24-Sep-12 20:07pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I assume that you need to check/uncheck gridview checkbox based on value present in the database. See below link, hope it helps you:
set-checkbox-in-gridview-based-on-datatable-value[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Do it on RowDataBound event of GridView.


protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
     CheckBox chk = (CheckBox)e.Row.FindControl("yourChekcBoxID");
     DataRowView drv = (DataRowView)e.Row.DataItem;

     chk.Checked = Convert.ToBoolean(drv["YourDataBaseField"]); 
  }
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

try below for 1 check box.

bool isChecked = (CheckBox)GridViewName.Rows.FindControl("chkBoxID")).Checked

Or

CheckBox ChkBox = (CheckBox)GridViewName.Rows.FindControl("chkBoxID")).value




try below methods for more than 1 check box

// Select the checkboxes from the GridView control
for (int i = 0; i < GridView1.Rows.Count; i++)
{
  GridViewRow row = GridView1.Rows[i];
  bool isChecked = ((CheckBox) row.FindControl("chkSelect")).Checked;

  if (isChecked)
  {
   
  }
}


Thanks,
  Permalink  
Comments
Afzal Shaikh 26-Sep-12 4:37am
   
whats wrong in it?

please provide valid reason if anyone going to be devoted the solution of anyone.

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

Solution 3

firstly what r u storing in database when your check box is checked ,i mean tiny int or Boolean ,suppose u r storing as tiny int then u should try like this

Check on row data bound event
protected void gvHardware_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      // find check box 
      CheckBox ChkBox = (CheckBox)GridViewName.Rows.FindControl("chkBoxID"));
      // Now check the column of data table according to that u will check or uncheck the grid check box 
      strCheck = ((DataRowView)e.Row.DataItem)["operation"].ToString();
      if(strCheck=="1")
      {
         ChkBox .Checked=true;
      }
   }
}

hope this will help u
Thanks
  Permalink  
v2

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
Web01 | 2.8.170118.1 | Last Updated 25 Sep 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