Tuesday, January 5, 2010

ListView and DataPager Controls in ASP.NET 3.5

ListView and DataPager are two new controls in ASP.NET.The ListView control supports the data editing, insertion, deleting, paging and sorting semantics of higher-level controls like the GridView. But, unlike the GridView, you have full control over the item templates of ListView, like Empty Item Template, Edit Item Template...


At first, you need provide a data source for your ListView. In my example, I use the SqlDataSource as a example. Then you add a ListView control to the page.

Now, you see this simple example from the browser.Notice above how I am using a <asp:placeholder> control in the <LayoutTemplate> to indicate where I want to add in my items in the list.  I could use other controls instead as the itemContainer if I wanted to - but by using an <asp:placeholder> control as the itemContainer I will prevent any id values or extra markup being generated. You can use <Div> <Table> <Panel> or other controls to contain the item. You should name the ID for itemContainer as itemPlaceholder.
Now you can add a DataPager control to the page

Here is just a simple sample, there are lots to configure, especially the ItemTemplate and LayoutTemplate

No comments:

Post a Comment