To achieve the effect is very simple, look at the picture:
Function: Select the checkbox, and then remove the selected item from the database. The article focuses on how to implement bulk deletion and does not explain how to link the database and bind the data in detail.
1 We first add a column checkbox to the GridView.The code is as follows:
Copy Code code as follows:
<asp:gridview id= "GridView1" runat= "Server" autogeneratecolumns= "false" >
<Columns>
<asp:boundfield datafield= "vote_id" headertext= "number"/>
<asp:boundfield datafield= "Vote_name" headertext= "name"/>
<asp:templatefield headertext= "Choice" >
<ItemTemplate>
<asp:checkbox id= "Cbxid" runat= "Server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Note that the ID is CBXID, we need to use it later.
2 binding data.
Copy Code code as follows:
Initializing data
private void Datainit ()
{
String sqltext = "SELECT * from vote";
SqlConnection conn = Getcon ();
SqlDataAdapter da = new SqlDataAdapter (Sqltext,conn);
DataSet ds = new DataSet ();
Conn. Open ();
Da. Fill (ds, "vote");
Gridview1.datasource = ds;
Gridview1.datakeynames = new string[]{"vote_id"};
Gridview1.databind ();
Conn. Close ();
Conn. Dispose ();
}
current 1/3 page
1 23 Next read the full text