With ASP. the release of NET 4.5 provides many new features. Among them, stronugly-Type Data-Bindings is very convenient for our development and the usage is very high, this blog post will share this new feature with you.
First, let's review the old data binding methods. For example, to bind data to the Repeater control, the following methods are usually used.
<Ul>
<Asp: Repeater ID = "Repeater1" runat = "server">
<ItemTemplate>
<Li>
<% # Eval ("FirstName") %>
<% # Eval ("LastName") %>
</Li>
</ItemTemplate>
</Asp: Repeater>
</Ul>
The backend data binding method remains unchanged, and the data source and DataBind () provided by DataSource are used ().
Protected void Page_Load (object sender, EventArgs e)
{
Using (var db = new WebFormsLab. Model. ProductsContext ())
{
This. customersRepeater. DataSource = db. MERs. ToList ();
This. customersRepeater. DataBind ();
}
}
In ASP. NET 4.5, the new feature of strong data binding is provided.ModelTypeSpecifies the full-qualified name of the strongly-typed object to be bound, providing a new data binding expression <% #: Item. property %>, the data binding of the above Repeater control adopts the new feature to implement the following code block.
<Ul>
<Asp: Repeater ID = "customersRepeater"
ModelType
= "WebFormsLab. Model. Customer"Runat = "server">
<ItemTemplate>
<Li>
<% #: Item. FirstName %>
<% #: Item. LastName %>
</Li>
</ItemTemplate>
</Asp: Repeater>
</Ul>
Please visit: http://www.asp.net/vNext