The first thing we need to do to see some data binding in action is to add a control that can actually take advantage of it. One of the simplest and most versatile controls to use has to be the new <asp:ListView>
control in ASP.NET 3.5.
The <asp:ListView>
control has a few nice features that make it ideal for data binding, especially in the dynamic web world with JavaScript and CSS. One of these features is the <LayoutTemplate>
block, which lets you specify a "wrapper" for the generated data.
If you're not quite sure what that means, it simply means that we want to create a set of tags to "wrap" our data. This could be the <ul>
tags for our <li>
data items, a set of <div>
or <table>
tags, or any other code.
In order to get the <LayoutTemplate>
to generate the same code we created earlier, we just need to add in our <ul>
tags with the class declaration, and an <asp:PlaceHolder>
with the ID of itemPlaceHolder...