ASP. NET datalist Control

Source: Internet
Author: User

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 ");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.