Design Template:
Header <HeaderTemplate>
</HeaderTemplate>
Footer <FooterTemplate>
</FooterTemplate>
Data Logging <ItemTemplate>
</ItemTemplate>
<AlternatingItemTemplate> Alternating Display items
</AlternatingItemTemplate>
<SelectedItemTemplate> How to display when selected
</SelectedItemTemplate>
<EditItemTemplate> How to display when editing
</EditItemTemplate>
<SeparatorTemplate> Data Record Separator
</SeparatorTemplate>
Edit templates, which can be embedded in controls, binding data.
<ItemTemplate>
<table>
<tr>
<td><%# DataBinder.Eval (Container.DataItem, "shareholding name")%></td>
<td><%# DataBinder.Eval (Container.DataItem, "market capitalisation", "{0:n}")%></td>
<td><%# DataBinder.Eval (Container.DataItem, "net", "{0:n}")%></td>
</tr>
</table>
</ItemTemplate>
Set appearance
RepeatLayout property setting display mode
RepeatDirection Display Direction
Number of RepeatColumns columns
Event
The button that joins the stencil column will raise its click event to the ItemCommand event or set the CommandName
To respond to different events, such as set to: Edit, which causes EditCommand (), and so on.
Note: If set to: Select will cause selectedindexchanged and ItemCommand events
SelectedItemTemplate template; A control that adds details, and when the user selects the item, the selection template is displayed.
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 the record is obtained here, as shown in the SelectedItemTemplate template.
Break
Case "Unselect":
This. Datalist1.selectedindex=-1;
Break
}
This. Datalist1.databind ()//Must be
}
EditItemTemplate Template
Edit:
This. Datalist1.edititemindex=e.item.itemindex;
This. Datalist1.databind ();
Update:
Get primary Key
String s= (String) this. Datalist1.datakeys[e.item.itemindex];
Get the controls in the stencil
TextBox box= (textbox) E.item.findcontrol ("TextBox1");
Update records
This. Datalist1.databind ();
Cancel:
This. Datalist1.edititemindex=-1;
This. Datalist1.databind ();
Delete Item
Check multiple records at once and delete them 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
}
}
Running custom DataList controls
When you create any item in 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 an item in a template is bound by data binding, the last chance that data is displayed before the client is accessed
private void Datalist1_itemdatabound (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;
I