asp.net bulk Deletion

Source: Internet
Author: User
asp.net bulk deletion

。 aspx files <asp:gridview id= "GridView1" runat= "Server" width= "100%" emptydatatext= "temporarily no data" bordercolor= "white" onrowde leting= "gridview1_rowdeleting" > <Columns> <asp:templatefie LD headertext= "Select" > <itemstyle width= "20px"/> <ItemTemplate> <asp:checkbox id= "id" runat= "Server"/> </ItemTemplate> </asp:TemplateField> <asp:boun
                            Dfield datafield= "id" headertext= "serial number" > <itemstyle width= "20px"/>
                                </asp:BoundField> <asp:templatefield headertext= "title" >
                                   <itemstyle width= "400px"/> <ItemTemplate> <a href= ".
                /shangpu/<% #eval_r ("Pageurl")%> "target=" _blank "><% #eval_r (" title ")%></a>                </ItemTemplate> </asp:TemplateField> & Lt;asp:templatefield headertext= "Publish Time" > <itemstyle Wi Dth= "100px"/> <ItemTemplate> <%# Convert. ToDateTime (Eval_r ("Addtime")). 
                            Date.tostring ("Yyyy-mm-dd")%> </ItemTemplate> </asp:TemplateField> <asp:hyperlinkfield Datanavigateurl formatstring= "shangpu_edit.aspx?id={0}" text= "Modify Navigateurl=" shangpu_edit.aspx?id={0} "DataNavigateUrlFields=" ID "> <itemstyle width=" 30px "/> &LT;/ASP:HYPERLINKFI eld> <asp:commandfield showdeletebutton= "True" headertext= Delete  deletetext= "<div id=" de "onclick=" javascript:return confirm (' OK delete it.
                            ' "> Delete </div>" > <itemstyle width= "30px"/>
                        </asp:CommandField> </Columns> <EmptyDataTemplate>
            <font color=red> temporarily no data </font> </EmptyDataTemplate>

 
 <rowstyle height= "20px"/> </asp:GridView>


。

        CS file protected void Btndeleteall_click (object sender, EventArgs e) {string sqltext = "("; for (int i = 0; i < GridView1.Rows.Count i++) {checkbox ChB = (CheckBox) gridview1.rows[i].
            FindControl ("id"); if (ChB. Checked) {sqltext = SQLText + gridview1.datakeys[i].
            Value.tostring () + ","; } SQLText = SQLText. Substring (0, SQLText.

        Length-1) + ")";

        SQLText = "Delete from Shangpu where id" + sqltext; String Sqlcon = configurationmanager.appsettings["ConnectionString"].

        ToString ();
        SqlConnection con = new SqlConnection (Sqlcon); Con.
        Open ();
        SqlCommand cmd = new SqlCommand (SQLText, con); try {int count = Convert.ToInt32 (cmd).
            ExecuteNonQuery ());
                if (Count > 0) {viewbind (); MessageBox.Show (This, "delete succeeded, delete total + count +" record.)
            ");
      }  The catch {MessageBox.Show (this, delete) failed.
        "); finally {con.
            Close (); Con.
        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.