<% # DataBinder.eval (Container.DataItem, "Net Value", "{0: N}")%> td>
TR>
TABLE>
Itemtemplate>
Set an appearance
REPEATLAYOUT attribute setting display mode
RepeatDirection display direction
REPEATCOLUMNS column
event
Add to the mandatory column to turn its Click event to the itemCommand event, you can also set up CommandName
To respond to different events, if you are: Edit, you will trigger editcommand ().
Note: If set to: SELECT will trigger SELECTEDEXCHANGED and ITEMCOMMAND events
SELECTEDITEMTEMPLATE template; add more information control, when the user selects this, select the template display.
Private void DataList1_itemCommand (...)
{
Switch (e.commandname)
{
Case "SELECT":
This.DataList1.selectedIndex = E.Item.itemindex;
String s = (string) this.datalist1.datakeys [E.Item.ItemIndex];
/ / The detailed data of this record is obtained here, displayed in the SelectEmtemplate template.
Break;
Case "unselect":
this.DataList1.selectedIndex = -1;
Break;
}
this.datalist1.databind (); // must
}
EditItemTemplate template
edit:
this.datalist1.edititemindex = E.Item.itemindex;
this.datalist1.databind ();
Update:
Get the primary key
String s = (string) this.datalist1.datakeys [E.Item.itemindex]; get controls in the template
TextBox Box = (TextBox) E.Item.FindControl ("TextBox1");
update record
this.datalist1.databind ();
cancel:
this.DataList1.edititeMindex = -1;
this.datalist1.databind ();
Delete
Check multiple records, delete once
Foreach (DatalistItem I in this.DataList1.Items)
{
Bool ischecked = (Checkbox) I.FindControl ("deletectr")). Checked;
IF (ischecked)
{
String s = (string) this.datalist1.datakeys [E.Item.ItemIndex];
Delete operation
}
}
Run custom DataList control
// When you create any of the DataList control
Private void DataList1_itemcreated (Object Sender, System.Web.ui.WebControls.DatalistiteMeventArgs E)
{
Switch (E.Item.ItemType)
{
Case ListItemType.Header:
E.Item.Forecolor = color.red;
E.Item.backcolor = color.black;
Break;
Case ListItemType.Item:
E.Item.backcolor = color.black;
Break;
}
}
/ / When the item in the template occurs when the item is bind, the data is displayed to the last opportunity to access before the client.
Private void DataList1_itemdatabase (Object Sender, System.Web.ui.WebControls.DataListiteMeventArgs E)
{
IF ((E.Item.ItemType == ListItemType.Header) || (E.Item.ItemType == ListItemType.Item))
{
System.data.common.dbdatarecord DRV =
(System.data.common.dbdatarecord) E.Item.DataItem;
IF ((Decimal) DRV ["stock"] <1000)
{
E.Item.Forecolor = color.red;
}
}
}
Another way
IF ((E.Item.ItemType == ListItemType.Header) || (E.Item.ItemType == ListItemType.Item))
{
DataRowView DRV = (DATAROWVIEW) E.Item.DataItem;
String Department = (string) DRV ["Department"];
Switch (Department)
{
Case "Sales":
E.Item.backcolor = color.black;
Break;
Case "Technical Department":
E.Item.backcolor = color.red;
Break;
}
}
转载请注明原文地址:https://www.9cbs.com/read-115859.html
|