Tuesday, June 22, 2010

Persisting row selection in data bound control like GridView,ListView

Some times we need show large amount of data like hundred of rows but its very difficult to show that in a single web page so we are using the paging mechanism of inbuilt data bound control of .NET Framework like GridView and ListView. But in paging of data bound control its very hard to remember the row selection like suppose you have selected a row in page 1 and then you goto the page2 and return back to page1 the selected row will not be there. So to do that thing you have right custom coding for that. In Microsoft .NET Framework 4.0 there is one property called EnablePersistedSelection which will automatically do that task. It will first introduced on dynamic data support in .NET Framework 3.5 sp1 but its bye default supported by default in .NET Framework 4.0 it self. In earlier version of .net framework the selection was based on row index now its will be based data key for data bound controls. Here is the code for that.

<asp:GridView id="PersitantGridView" runat="server" EnablePersistedSelection="true">
</asp:GridView>
Its based on datakey so now you go to page1 and selected third row and then go to the page 2 and selected second row and now you again go to first page and you will have third row selected. That’s it.. Hope this will help you..

Technorati Tags: ,,
Shout it
kick it on DotNetKicks.com
Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews