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?