Implementation of batch Delete of gridview under Asp.net page 1/3

Source: Internet
Author: User

The effect to be achieved is very simple. For more information, see:

Function: Select the checkbox, and then delete the selected items from the database.ArticleIt focuses on how to implement batch deletion and does not explain how to connect to the database and bind data in detail.

1 first, add a column as checkbox in the gridview.CodeAs follows:Copy codeThe Code is as follows: <asp: gridview id = "gridview1" runat = "server" autogeneratecolumns = "false">
<Columns>
<Asp: boundfield datafield = "vote_id" headertext = "no."/>
<Asp: boundfield datafield = "vote_name" headertext = "name"/>
<Asp: templatefield headertext = "select">
<Itemtemplate>
<Asp: checkbox id = "cbxid" runat = "server"/>
</Itemtemplate>
</ASP: templatefield>
</Columns>
</ASP: gridview>

Note that the ID is cbxid and will be used later.

2. Bind data.Copy codeThe Code is as follows: // initialize 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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.