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
// 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.
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.