ASP. NET learning: Use of datalist

Source: Internet
Author: User

Datalist control application. It can process user click events.
In the aspx code: <asp: datalist id = "datalist2 ".......
Add onitemcommand = "datalist_itemcommand"

Then add the following C # code:
Void bindlist () // use datalist2
{
String commstr = "select * from % #";
Oledbdataadapter myadapter = new oledbdataadapter (commstr, dbconn );
Dataset DS = new dataset ();
Myadapter. Fill (DS, "khda ");

Datalist2.datasource = Ds. Tables ["khda"]. defaultview;
Datalist2.databind ();
}

Void datalist_itemcommand (Object sender, datalistcommandeventargs E)
{
Datalist2.selectedindex = E. Item. itemindex;
Bindlist ();
}

Original table:

Click "details" to display the following information:

Of course, you must set selecteditemtemplate in datalist.

<TD> details </TD>
<TD colspan = "3">
Customer name: <% # databinder. eval (container. dataitem, "khmc") %>
<Br>
Address: <% # databinder. eval (container. dataitem, "khdz") %>
<Br>
Customer Phone: <% # databinder. eval (container. dataitem, "khdh") %>
<Br>
Registration Date: <% # (datetime) databinder. eval (container. dataitem, "djrq") %>
</TD>

Also, settings of itemtemplate:
<Tr style = "font-size: 14px">
<TD>
<Asp: linkbutton id = "buttona" runat = "server" text = "detailed data"
Commandname = "select"/> </TD>
<TD style = "font-size: 11pt; color: #66cc66"> <% # databinder. eval (container. dataitem, "khbh") %> </TD>
<TD style = "font-size: 11pt; color: #66cc66"> <% # databinder. eval (container. dataitem, "khmc") %> </TD>
</Tr>









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.