Datalist Control
Buttons for viewing details
1. Add a button in the general item template to set the commandname attribute of the button to "select"
2. Select rows in the itemcommand event of datalist
Code
Protected void datalist1_itemcommand (Object source, datalistcommandeventargs E)
{
If (E. commandname = "select ")
{
This. datalist1.selectedindex = E. Item. itemindex;
This. datalist1.databind ();
}
}
3.Display the information to be displayed in the selected Template
<Selecteditemtemplate>
<% # Databinder. eval (container. dataitem, "title") %>
Release date: <% # databinder. eval (container. dataitem, "publishdate", "{0: d}") %>
<% # Databinder. eval (container. dataitem, "contentdescription") %>
</Selecteditemtemplate>
GirdviewWidget
Add field page:
Hyperlinkfield hyperlink
Main attributes:
Name of the data source field to be bound to datanavigateurlfields
Datanavigateurlformatstring will be submitted to the target page in get mode, for example, bookdetail. aspx? Id = {0}
What is next to the connection? Id = is the submission address {0} is a placeholder
Or:
For example, the page to be submitted is an ordered page. It names the Page name based on the ID field in the table.
The datanavigateurlfields attribute is bookname.
The datanavigateurlformatstring attribute is books/{0}. aspx.
RowdataboundEvent enables the mouse to hover over the current row to change color
Code
Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. datarow) // if the current row type is data row
{
// Add an attribute to the currently bound row
// Set the background to Blue e when you hover the mouse over. row. attributes. add ("onmouseover", "currentcolor = This. style. backgroundcolor; this. style. backgroundcolor = '# 6699ff '");
// Restore the background color when the mouse leaves
E. Row. Attributes. Add ("onmouseout", "This. style. backgroundcolor = currentcolor ");
}
}