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.

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

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 [email protected]Ankit Goyal

More Posts - Website

  • Pingback: DotNetShoutout()

  • Pingback: ASP.NET 4.0 – Persisting Row Selection in Data Controls | TechArtifact - asp()

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

  • 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!

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

  • What a great resource!

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

  • 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.