to add checkbox in asp.net in gridview

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 18
Reputation: mailtosridar is an unknown quantity at this point 
Solved Threads: 0
mailtosridar mailtosridar is offline Offline
Newbie Poster

to add checkbox in asp.net in gridview

 
0
  #1
Oct 8th, 2008
help me how to add checkbox in gridview in asp.net(by coding)
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 6
Reputation: zezo is an unknown quantity at this point 
Solved Threads: 0
zezo's Avatar
zezo zezo is offline Offline
Newbie Poster

Re: to add checkbox in asp.net in gridview

 
0
  #2
Oct 9th, 2008
1. right click on your DataGrid -->Property Builder -->Columns --> Template Column --> Apply --> Ok.
2. Right click again --> EidtTemplate --> choose Column you add --> drag CheckBox control from Toolbox and drop it in ItemTemplate field and if you need CheckBox in edit mode put another CheckBox control in EditItemTemplate field --> End Template Editing.

Code on the button:
  1. private void btn_Delete_Click(object sender, System.EventArgs e)
  2. {
  3. for(int i=0;i<dg_EditProduct.Items.Count;i++)
  4. {
  5. CheckBox chk = new CheckBox();
  6. chk = (CheckBox)dg_EditProduct.Items[i].FindControl("chk_Delete");
  7. if(chk.Checked)
  8. {
  9. DataTable myTable;
  10. myTable=(DataTable)Session["ProductTable"];
  11. int ID_Delete = Convert.ToInt32( myTable.Rows[i]["ProductID"]);
  12.  
  13. Str_Conn = ConfigurationSettings.AppSettings["Fashion"];
  14. MyConn = new SqlConnection(Str_Conn);
  15.  
  16. //Command to delete Product
  17. // SqlCommand cmd_DeleteProduct = new SqlCommand("dbo.DeleteProduct",MyConn);
  18. SqlCommand cmd_DeleteProduct = new SqlCommand("DeleteProduct",MyConn);
  19. cmd_DeleteProduct.CommandType = CommandType.StoredProcedure;
  20. SqlParameter ProductID_Delete = cmd_DeleteProduct.Parameters.Add("@ProductID",SqlDbType.Int);
  21. ProductID_Delete.Value = ID_Delete ;
  22.  
  23. MyConn.Open();
  24. dg_EditProduct.DataSource = myTable;
  25. cmd_DeleteProduct.ExecuteNonQuery();
  26. MyConn.Close();
  27. }
  28. }
  29. BindData(); // it is the function you use to bind data to datagrid on page load
  30. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC