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 provides the new feature of strong-type data binding. The ModelType of the control specifies the full-qualified name of the strong-type object to be bound, and provides the 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>
From the notes for growing up in the B omnia Workshop