In general CMS (Content Manager System), batch operations are inevitable. For example, if a page of data is displayed, operations such as batch deletion and batch recommendation will be added to a good design.
In ASP. NET, this batch operation is very simple. Taking batch deletion as an example, we only need the checkbox control for multiple selections and a batch deletion button. The Repeater control is used to display data.
Below is a section of my projectCode:
Aspx front-end file code:
<Table> <tbody> <tr> <thclass = "th_checkbox"> </Th> <thclass = "th_floor"> floor number </Th> <thclass = "th_room"> room No. </Th> <thclass = "th_computernumber"> Computer No. </Th> <thclass = "th_proname"> problem name </Th> <thclass = "th_protype"> Problem type </Th> <thclass = "th_prodescription"> Problem description </Th> <thclass = "th_operate"> operation </Th> </tr> <asp: repeaterid = "unprorepeater" runat = "server"> <itemtemplate> <tr> <TD> <asp: checkbox id = "cddelete" tooltip = '<% # eval ("ID") %> 'text = "" runat = "server"/> </TD> <% # eval ("floor ") %> </TD> <% # eval ("rmnumber") %> </TD> <a href = 'addunfinishedpro. aspx? Id = <% # eval ("ID") %> '> <% # eval ("cmnumber ") %> </a> </TD> <% # eval ("name") %> </TD> <% # eval ("typename ") %> </TD> <% # cutstring (eval ("Description "). tostring (), 15 ,"... ") %> </TD> <asp: linkbutton id =" lbtndelete "commandargument = '<% # eval (" ID ") %> 'onclientclick = "returnconfirm ('Are you sure you want to delete it? ') "Onclick =" lbtndelete_click "runat =" server "> Delete </ASP: linkbutton> </TD> </tr> </itemtemplate> </ASP: repeater> </tbody> </table>
Don't be scared by this Code. Only the <TH class = "th_checkbox"> </Th> block in the first <tr> </tr> block is really useful, the purpose is to leave a column for a single sequence; <TD> <asp: checkbox id = "cddelete" tooltip = '<% # eval ("ID") %> 'text = "" runat = "server"/> </TD>, display the checkbox control. The tooltip attribute is used to carry the record ID. With the record ID, we can operate this record. Why is this attribute used? Because this attribute is the most suitable, it is surprising that ASP. net checkbox does not have the value attribute. Find it and find it. Only the tooltip attribute can be used to carry the ID. If you place the cursor on the checkbox, the record ID will be displayed.ProgramIs mysterious. After the Repeater control is bound to the data, a single shard is added before each data entry, which achieves the goal. As an example, the above Code does not need to be written so much, but the Code is fully written to give readers a complete demonstration.
Add another batch delete button on the interface, and the foreground will be ready. How can I delete the selected items in the batch delete button event?
Aspx. CS background code:
Protected void btndelete_click (Object sender, eventargs e) {bool result = true; // traverses the itemtemplate template foreach (repeateritem item in unprorepeater. items) {checkbox cb = (checkbox) item. findcontrol ("cddelete"); // obtain the control object based on the control ID. cddelete is the ID of the checkbox control if (CB. checked = true) {// delete operation, delete records by ID, CB. the tooltip stores the record ID} // do not forget to re-bind the data after deletion ..... }
A detailed comment has been added to the Code, so you can understand it at a glance.
This simple example shows how ASP. NET performs batch operations through the Repeater control and checkbox control. It is helpful for everyone to learn!