Custom templates for ASP. NET Data Controls

Source: Internet
Author: User
The DataGrid, datalist, and repeater Data Controls Support the template function. For example, the following is the datalist item template,

< ASP: datalist ID = " Datalist1 " Runat = " Server " Enableviewstate = " False " >
< Itemtemplate >
<% # Databinder. eval (container, " Dataitem. ID " ) %>
</ Itemtemplate >
</ ASP: datalist >

In general, this template isProgramWhat we need to do now is how to dynamically change the template item definition at runtime.

First, create an ascx user-defined control with the following content:

< Table ID = " Table1 " Cellspacing = " 0 " Cellpadding = " 0 " Width = " 100% " Border = " 1 " >
< Tr >
< Th > Operation </ Th >
< Th > User Name </ Th >
< Th > Forum ID </ Th >
< Th > Email </ Th >
< Th > Quota </ Th >
< Th > Administrator </ Th >
</ Tr >
< Tr >
< TD > <% # Databinder. eval (container, " Dataitem. ID " ) %> </ TD >
< TD > <% # Databinder. eval (container, " Dataitem. uid " ) %> </ TD >
< TD > <% # Databinder. eval (container, " Dataitem. bbsid " , " <A href = "" Javascript: showbbsid ('{0 }'); "" > {0} </a> " ) %> </ TD >
< TD > <% # Databinder. eval (container, " Dataitem. Email " ) %> </ TD >
< TD > <% # Databinder. eval (container, " Dataitem. pur " ) %> </ TD >
< TD > <% # Databinder. eval (container, " Dataitem. OP " ) %> </ TD >
</ Tr >
< Tr >
< TD colspan = " 6 " >
< Table ID = " Table 2 " Cellspacing = " 0 " Cellpadding = " 0 " Width = " 100% " Border = " 0 " >
< Tr >
< TD > Reason: </ TD >
</ Tr >
< Tr >
< TD > <% # Databinder. eval (container, " Dataitem. memostr " ) %> </ TD >
</ Tr >
< Tr >
< TD > < HR > </ TD >
</ Tr >
< Tr >
< TD > Certification description: </ TD >
</ Tr >
< Tr >
< TD > <% # Databinder. eval (container, " Dataitem. Excuse " ) %> </ TD >
</ Tr >
</ Table >
</ TD >
</ Tr >
</ Table >

Of course, the above example is just an example. You can also create a template file by yourself. Note that the extension must be. ascx,CodeThe specification must be the rule of the template column.

After the template is created, what we need to do is to call it in the program. Step 1: Add a blank datalist control at the corresponding position of the page and add a code to the page_load event:

Datalist1.itemtemplate=Page. loadtemplate ("Test. ascx")

Then you can bind the database... How is it? Simple?

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.