Almost all the DataBound controls support templates. You can use a template to format the layout and appearance of each of the data items that a DataBound control displays. Within a template, you can use a DataBinding expression to display the value of a data item.
Every DataBound control included in the ASP.NET 2.0 Framework supports templates with the sole exception of the treeView control. The Repeater, DataList, and FormView controls all require you to use templates. If you don't supply a template, then these controls display nothing. The GridView, DetailsView, and Menu controls also support templates, but they do not require a template. A template can contain HTML, DataBinding expressions, and other controls.
Example :
< %@ Page Language="VB" %>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
< html xmlns="http://www.w3.org/1999/xhtml" >
< head id="Head1" runat="server">
< title>Show Links< /title>
< /head>
< body>
< form id="form1" runat="server">
< div>
< asp:Repeater
id="Repeater1"
DataSourceId="srcStudent"
Runat="server">
< ItemTemplate>
< asp:HyperLink
id="HyperLink1"
Text='<%# Eval("name") %>'
NavigateUrl='<%# Eval("id", "Details.aspx?id={0}") %>'
runat="server" />
< br />
< /ItemTemplate>
< /asp:Repeater>
< asp:SqlDataSource
id="srcStudent"
ConnectionString="Data Source=.\SQLExpress;
AttachDbFilename=|DataDirectory|Data.mdf;
Integrated Security=True;User Instance=True"
SelectCommand="SELECT id, name FROM student"
Runat="server" />
< /div>
< /form>
< /body>
< /html>
No comments:
Post a Comment