Keep mulitple ListViews on the same page.
December 15, 2009
I just had a project that required me to have a list of articles both in the the left nav and main content area.
In the left nav is was just a list of the titles. The titles were links to anchors in the main page since the actual articles were a bit lengthy.
The client only wanted 5 articles to be displayed per page. So paging was needed. I used two separate ListViews to display the news items. Along with that each ListView had a DataPager to handle the paging.
The trick was if a user clicked on page 2 in the left nav how would we update the main content ListView to move to page 2 as well?
To accomplish this I accessed the PagePropertiesChanging handler and updated both DataPager PageProperties.
So if a user clicked in the left nav the code-behind is:
protected void lvLeftNav_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
dpNews.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
dpLeftNav.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
BindNews();
}
As you see I update both DataPagers.
Here is the code-behind for the main news content code-behind:
protected void lvNews_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
dpNews.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
dpLeftNav.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
BindNews();
}
I should mention that the BindNews() method handles binding both the Left Nav and Main News to the same News List<News>.
-
anonymous
-
Joel
-
Categories
- asp.net (11)
- Blog (1)
- Business (5)
- Conferences (1)
- Errors (3)
- Portfolio (2)
- Reviews (2)
- SQL Server (3)
- Tips (1)
- Uncategorized (1)
- Web Development (13)
-
Archives