Datalist simultaneously selected to delete multiple

Source: Internet
Author: User

Execution result: Put the checkbox and the data to be displayed in the datalist item template. After selecting a series of checkboxes, click the delete all button to delete the selected items at the same time, determine whether to delete data.

The delete all button is placed in the datalist item template. datakeyfield of datalist is set as the primary key of each item.

Bool flag = false; // defines whether a flag deletes data.
Foreach (datalistitem DLT in datalist1.items) // cyclically retrieve each item in datalist
{
// Use the findcontrol method of datalistitem to find the checkbox. The parameter is the ID of the checkbox. the return value is of the control type and is converted to the checkbox type.
Checkbox ckb = (checkbox) DLT. findcontrol ("cbdelete ");
If (ckb. Checked) // checks whether the checkbox is selected.
{
Int id = convert. toint32 (datalist1.datakeys [DLT. itemindex]); // retrieves the primary key of datalist for database deletion.
Postoperate po = new postoperate (); // instantiate the encapsulated data operation class
Flag = Po. Delete (ID); // The delete method in the execution class to delete data. If the deletion is successful, true is returned. If no data is deleted, the flag is false.
}
}
If (FLAG) // determine whether data is deleted based on the flag value
{
JS. alertandreturn (this. Page, "the article is deleted successfully! "," Postmanager. aspx ");
}
Else
{
JS. alertandreturn (this. Page, "No items to delete are selected! "," Postmanager. aspx ");
}

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.