[ASP.NET 4.0] Persisting Row Selection in Data Controls

Posted by HosamKamel on ASP.net Weblogs See other posts from ASP.net Weblogs or by HosamKamel
Published on Sun, 09 May 2010 20:33:20 GMT Indexed on 2010/05/09 20:38 UTC
Read the original article Hit count: 1764

Data Control Selection Feature In ASP.NET 2.0:

ASP.NET Data Controls row selection feature was based on row index (in the current page), this of course produce an issue if you try to select an item in the first page then navigate to the second page without select any record you will find the same row (with the same index) selected in the second page!

In the sample application attached:

  • Select the second row in the books GridView.
  • Navigate to second page without doing any selection
  • You will find the second row in the second page selected.

image image

Persisting Row Selection:

  • Is a new feature which replace the old selection mechanism which based on row index to be based on the row data key instead.
  • This means that if you select the third row on page 1 and move to page 2, nothing is selected on page 2. When you move back to page 1, the third row is still selected.

Data Control Selection Feature In ASP.NET 3.5 SP1:

  • The Persisting Row Selection was initially supported only in Dynamic Data projects

Data Control Selection Feature In ASP.NET 4.0:


  • Important thing to note, once you enable this feature you have to set the DataKeyNames property too because as discussed the full approach is based on the Row Data Key

image image

Simple feature but  is a much more natural behavior than the behavior in earlier versions of ASP.NET.

Download Demo Project

Digg This

© ASP.net Weblogs or respective owner

Related posts about Weblog.asp.net

Related posts about Web Application Project