Use DataList

xiaoxiao2021-04-09  345

This is a title with obvious inflammatory, yes, here is the proposal to use DataList. In the MSDN Chinese Station, there is an article about the performance test of Repeater, DataList and DataGrid. I also transfer this article to my station. "Reprint, I hope you will accept my lesson, I have to do it, this is the article Nice article, there is a detailed analysis of these three controls. It can be clearly seen from performance comparison to see that Repeater and DataList have no difference in efficiency, while DataList and Repeater have a lot of excellent performance. Of course, when you are using simple processing, it is still useful, but if you want to do a "message" level system, you will have a significant advantage in DataList!

Figure: Performance is more than a detailed talk about this Datalist, we use it mainly because it has four commands Select / Edit / Update / Cancel, and the corresponding two templates SelectedItemtemtemtemtemtemtemtemtemtemtemtemtemtemtemtemtemTemplate / EditItemTemplate. According to my observation, It seems that every time you click the button to perform the action, you will trigger the event specified by OnItemCommand, so everyone must pay attention when using OnItemCommand. But we can also use this feature to use the delete command lacking in DataList, the method is to add a < / asp: linkbutton>, because every click button must execute the DataList_onselectedCommand event specified by OnItemCommand, we can add the definition of the delete event in this:

// Event time

Private Void DL1_SELECTED (Object Sender, DatalistCommandeventEventArgs E) {

//Delete Record

IF (e.commandname == "delete") {

// Do Something About Delete

}

// End Delete Record

Else {

DL1.SelectedIndex = E.Item.ItemIndex;

set ();

lb2.text = "SELECT";

}

}

This completes a delete process. Similarly, if you need to define what other features, you can also put it in this. Finally, let's talk about DataList's way of work, and friends who are not very familiar with Datalist can then read down. This is a simple reference to the DataList control to specify the handler of the event. DataList the selecteditemtemplate / edititemtemplate template is not displayed on the start page , But when the user clicks the button of CommandName for the SELECT / EDIT, it is said to what we said above, when not specified for any Select or Edit's commandName, SelectedItemTemplate will come out, and when you put When CommandName is set to Edit / Update / Cancel, this SelectedItemTemplate will not appear. // Click Edit torsion Events

Private Void DL1_EDIT (Object Sender, DataListCommandeventArgs E) {

DL1.EDITEMINDEX = E.Item.ItemIndex;

set ();

}

/ / Click to cancel the button event

Private void DL1_Cancel (Object Sender, DatalistCommandeventArgs E) {

DL1.EDITEMINDEX = -1;

set ();

}

/ / Click to update the transformation event

Private Void DL1_UPDATE (Object Sender, DatalistCommandeventArgs E) {

// Do Something About Update

}

According to the code above, the edititemtemplate will appear when edit, and the point Cancel will return to SELECT. Say is some of the DataList's command, actually to have our own yourself.

转载请注明原文地址:https://www.9cbs.com/read-133074.html

New Post(0)