ASP.NET bind single instance data
I have a data class that I want to show in a list on one page and also alone in another page. I know how to do the first:
<asp:Repeater ID="ctrl" runat="server">
<ItemTemplate>
Here's the name: <asp:Literal runat="server" Text='<%# Eval("Name") %>'开发者_如何转开发 />
</ItemTemplate>
</asp:Repeater>
On the other page, I want to show exactly one instance, and I want to reuse the item template. Is there a control that I can bind to a single instance of this class, instead of a list which contains a single element?
You can use the same Repeater
but with a DataSource
of on specific record/instance.
You can also use FormView
control.
The FormView control gives you the ability to work with a single record from a data source. The FormView control does not specify a pre-defined layout for displaying the record. Instead, you create a template containing controls to display individual fields from the record. For information about programming the FormView control, see FormView Class in the MSDN library.
精彩评论