ASP.NET 4.0 – Persisting Row Selection in Data Controls

By Ankit Goyal | May 25, 2010 | 1,208 views
Category .NET

  Share


About author  Working on .NET technologies for past 2yrs. 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 Read more from this author


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

  • Delicious
  • Yahoo Buzz
  • Digg
  • DZone
  • Facebook
  • LinkedIn
  • Twitter
  • Share/Bookmark
Read more post on ASP.NET 4.0 Microsoft 

  Share

6 comments | Add One

Comments

  1. emt trainingNo Gravatar - 05/30/2010 at 2:51 pm

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



  2. medical assistantNo Gravatar - 06/3/2010 at 12:04 am

    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 robotNo Gravatar - 06/6/2010 at 1:04 am

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



  4. government grantsNo Gravatar - 06/12/2010 at 9:02 pm

    What a great resource!



Trackbacks

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

Leave a Comment

Name:

E-Mail :

Website :

Comments :