.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

checkbox checked in GridView?

Posted By: Shweta     Posted Date: August 03, 2010    Points:2   Category :ASP.Net
Hi,

I have a gridview which contains columns retreived from the database.i have in total 12 columns,in which 4 columns have checkbox's where ever there is a null in the database.i have done tht on the rowdatabound event of gridview dynamically by calling

CheckBox cb= new CheckBox();

now my question is,i want to check the boxes in the column cells and update those values in the database on button click.i also have a checkbox in the first column of the gridview created using an itemTemplate tag of gridview,so tht when we check the corresponding row's checkbox,the values in tht row shall be updated......any responses will be appreciated.

Thanks,
Shweta

Responses
Author: Syed Shakeer Hussain             
Posted Date: August 04, 2010     Points: 5   

Hi,
protected void GridViewCheck_Click(object sender, EventArgs e) 
{
for (int i = 0; i < Gridview1.Rows.Count; i++)
{
CheckBox chkb = (CheckBox)Gridview1.Rows[i].Cells[0].FindControl("chk");
if (chkb.Checked)
{
string id = Gridview1.Rows[i].Cells[2].Text;
//Write your Update Command here....
SqlCommand cmd=new SqlCommand("update tablename set name='"+textname.Text+"' where id='"+id+"'",conn);
cmd.ExecuteNonQuery();

}
}
}


Author: Clintonzz             
Posted Date: April 23, 2014     Points: 20   

This reminded me of the C# gridview checkbox column:

http://www.kettic.com/winforms_ui/csharp_guide/gridview_column_types_checkbox_column.shtml

Hope this be helpful.



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend