help me how to add checkbox in gridview in asp.net(by coding)

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:

private void btn_Delete_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<dg_EditProduct.Items.Count;i++)
			{   
				CheckBox chk = new CheckBox();
				chk = (CheckBox)dg_EditProduct.Items[i].FindControl("chk_Delete");
				if(chk.Checked)
				{   
					DataTable myTable;
					myTable=(DataTable)Session["ProductTable"];
					int ID_Delete = Convert.ToInt32( myTable.Rows[i]["ProductID"]);

					Str_Conn = ConfigurationSettings.AppSettings["Fashion"];
					MyConn = new SqlConnection(Str_Conn);
					
					//Command to delete Product
//					SqlCommand cmd_DeleteProduct = new SqlCommand("dbo.DeleteProduct",MyConn);
					SqlCommand cmd_DeleteProduct = new SqlCommand("DeleteProduct",MyConn);
					cmd_DeleteProduct.CommandType = CommandType.StoredProcedure;
					SqlParameter ProductID_Delete = cmd_DeleteProduct.Parameters.Add("@ProductID",SqlDbType.Int);
					ProductID_Delete.Value = ID_Delete ;

					MyConn.Open();
					dg_EditProduct.DataSource = myTable;
					cmd_DeleteProduct.ExecuteNonQuery();
					MyConn.Close();
				}
			}
			BindData(); // it is the function you use to bind data to datagrid on page load
		}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.