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

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

1 Comment

  • yes it's really a powerful new feature because previously i was doing more effort to make it eg :

    ((e.Row.RowIndex + 1) + (GridView1.PageIndex * GridView1.PageSize)).ToString();

Comments have been disabled for this content.