In the aspx fileCode:
<Asp: datalist id = "lbdatalist" runat = "server" repeatcolumns = "2" repeatdirection = "horizontal"
Skinid = "foo" Onitemcommand = "lbdatalist_itemcommand"> // The red part is effective in mojoportal.
<Itemtemplate>
<Table>
<Tr>
<TD>
<% # Eval ("lblc") %>
</TD>
<TD>
<Asp: linkbutton id = "datalist_delete" runat = "server" commandname = "delete" causesvalidation = "false"
TEXT = "delete" cssclass = "delete-link" commandargument = '<% # databinder. Eval
(Container. dataitem, "ID") %> '> </ASP: linkbutton>
</TD>
</Tr>
</Table>
</Itemtemplate>
</ASP: datalist>
In the Aspx. CS file, the "delete" feature of datalist is as follows:
// Of course, only one of the following three methods can be used to implement "delete !!
// method 1 of the "delete" function in datalist:
// In the "design" Mode on the page, select datalist, double-click the blank area on the right of "property" -- "Event"
// to automatically generate an empty method, then implement the deletion function
// (a sentence is automatically generated in the label:
// ondeletecommand = "lbdatalist_deletecommand")
protected void lbdatalist_deletecommand (Object source, datalistcommandeventargs e)
{< br> decimal id = convert. todecimal (E. commandargument); // get the ID to be deleted? Is the row ID of datalist or the data ID?
************ Add code here to "delete" ***********
// Bind again
* ********** Add code here and bind it again to see the effect after deletion **********
}
// Method 2:
// In the "Source" mode of the page, add the following command in <asp: linkbutton> </ASP: linkbutton>:
// Oncommand = "delete" (note: the two "delete" must be the same, and C # Is case sensitive)
// Add the following method to the CS code:
Protected void Delete (Object sender, commandeventargs E)
{
Decimal id = convert. todecimal (E. commandargument); // get the ID to be deleted? Is the row ID of datalist or the data ID?
* ********** Add code here to "delete "**********
// Bind again
* ********** Add code here and bind it again to see the effect after deletion **********
}
// method 3:
// In the "Source" mode of the page, in Add the following command:
// onitemcommand = "lbdatalist_itemcommand"
// (Note: Add oncommand = "delete" command)
// Add the following method to the CS code:
protected void lbdatalist_itemcommand (Object source, datalistcommandeventargs E)
{< br> decimal id = convert. todecimal (E. commandargument);
************ Add code here, to obtain the object to be deleted **********
If (E. commandname = "delete ")
{
* ********** Add code here to achieve "delete "**********}
// Bind again
* ********** Add code here and bind it again to see the effect after deletion **********
}