Problem Statement
In older versions of ASP.NET, When we select any row in a GridView or ListView controls, the selection is based on the row index of the page. For example, If we select row no 3 on page 1 and then move to page 2, we will see row no 3 again selected on page 2. which is undesirable.

Solution
ASP.NET 4.0 introduces the feature of Persisted Selection. When this feature is enabled, the selected item is based on the row datakey and not row index. For example, in a Grid showing products, i can specify that DataKey for my products is “ISBN”. Hence the rows will now be selected on the basis of ISBN(i.e. Datakey). Which further means that if i select row no 3 in products grid on page 1 and then move to page 2, no row will be selected. But if i again go back to page 1, row 3 will still be selected.

Feature can be enabled/disabled by setting the property EnablePersistedSelection. Also the property DataKeyNames be specified so that DataKey is set for the rows.

References: MSDN

kick it on DotNetKicks.com

Shout it

Anky Goyal

I am MCPD certified in .NET and working on .NET technologies for past 3yrs. I am very passionate about the new features which get introduced in the technology. I am here to share the new features i get to know in the world of Microsoft. Follow me on twitter @ankygoyal LinkedIN@Ankit Goyal

More Posts - Website

8 Responses to ASP.NET 4.0 – Persisting Row Selection in Data Controls


  1. emt training
    May 30, 2010

    Great site. A lot of useful information here. I’m sending it to some friends!


  2. medical assistant
    Jun 03, 2010

    This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post. Thanks!


  3. forex robot
    Jun 06, 2010

    My cousin recommended this blog and she was totally right keep up the fantastic work!


  4. government grants
    Jun 12, 2010

    What a great resource!


  5. Kenneth Mustin
    Jul 25, 2011

    writing sequence is awesome, I generally look for top quality material, thanks for sharing


  6. ps3 headset 2.0
    Aug 25, 2011

    I used to be very pleased to find this web-site.I wanted to thanks in your time for this wonderful read!! I definitely having fun with every little bit of it and I’ve you bookmarked to take a look at new stuff you weblog post.

Trackbacks/Pingbacks

  1. DotNetShoutout
  2. ASP.NET 4.0 – Persisting Row Selection in Data Controls | TechArtifact - asp

Leave a Reply