AlmostAllAll data binding controls support templates ).
InShow dataYesUse a template to format the layout and appearance of each data item.
With the template, you canEnableUse a data binding expression to display the value of a data item.
Use Template
(Except for Treeview) data binding control in 2.0Templates are supported.
Repeater, datalist, and formview must use templates to display data.
Supported templates, such as gridview, detailsview, and menu, are not required.
The template can contain
- Html
- Data Binding expression
- Other controls
Example: hyperlink list
<% @ Page Language = " VB " %> <! Doctype html Public " -// W3C // dtd xhtml 1.0 transitional // en " " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " > <SCRIPT runat = " Server " > </SCRIPT> <HTML xmlns = " Http://www.w3.org/1999/xhtml " > <Head runat = " Server " > <Title> display link </title> " Form1 " Runat = " Server " > <Div> <asp: repeater id = " Repeater1 " Runat = " Server " Performanceid =" Srcmovies " > <Itemtemplate> <asp: hyperlink id = " Hyperlink1 " Runat = " Server " Navigateurl = ' <% # Eval ("ID", "details. aspx? Id = {0} ") %> '> <% # eval (" title ") %> </ASP: hyperlink> <Br/> </itemtemplate> </ASP: repeater> <asp: sqldatasource id = " Srcmovies " Connectionstring = " Data Source =. \ sqlexpress; Integrated Security = true; user instance = true; attachdbfilename = | datadirectory | mydatabase. MDF " Selectcommand = " Select ID, title from movies " Runat = " Server " /> </Div> </form> </body>
<% @ Page Language = " VB " %> <! Doctype html Public " -// W3C // dtd xhtml 1.0 transitional // en " " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " > <SCRIPT runat = " Server " > </SCRIPT> <HTML xmlns = " Http://www.w3.org/1999/xhtml " > <Head runat = " Server " > <Title> " Form1 " Runat = " Server " > <Div> <asp: gridview id = " Gv1 " Performanceid = " Srcmovies " Runat = " Server " > </ASP: gridview> <asp: sqldatasource id = " Srcmovies " Connectionstring = " Data Source =. \ sqlexpress; Integrated Security = true; user instance = true; attachdbfilename = | datadirectory | mydatabase. MDF " Selectcommand = " Select title, Director from movies where id = @ mid " Runat = " Server " > <Selectparameters> <asp: querystringparameter name = " Mid " Type = " Int32 " Querystringfield = " ID " /> </Selectparameters> </ASP: sqldatasource> </div> </form> </body>
Use a data binding expression
Data Binding expressionRuntimeTo calculate the result.
(Used on the page) as long as the expressionIncluded in the <% # %> symbol.
Data Binding expressionWhen the databinding event of the control is triggeredTo start calculating the value.
For the [declarative data binding] event isAutomatically triggered.
For the [programmatic data binding] event inTriggered when databind method is called.