ASP. NET 4.5 new feature 1: stronugly-Type Data-Bindings)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.