GridView SelectedDataKey paging problem

O

otto

Hi,
I have a GridView where I've implemented paging along with a Button that
uses the CommandName "Select". When I render the page initially, I click
the button and handle the SelectedIndexChanged event and get the
SelectedDataKey values as expected. When I change the page on the grid, I
get a null value for the SelectedDataKey instead of the DataKey values. Any
idea where I might be going wrong here?
 
S

Steven Cheng[MSFT]

Hi Otto,

Welcome to the ASP.NET newsgroup.

As for the read GridView control's selected item datakey when page index
changes problem, it is the expected behavior and there is nothing incorrect
in your code. Actually, the current selectedDataKey is based on the
SelectedIndex, and this index value is page index specific. For example, if
our GridView's Page size is 3 and have 8 records totally, it will display
3 pages. And if we select the second record(on the first page), the
GridView's SelectedIndex will become 1, However, if we change page index to
1 to view the second page, since the SelectedIndex remain 1, it actually
point to the 5th data record. And if the selectedIndex dosn't point to any
record on a certain page, the "SelectedDataKey" or "SelectedValue" become
empty. So we need to take care of the current selected item when paging
index changes.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,139
Messages
2,570,806
Members
47,352
Latest member
Maricruz09

Latest Threads

Top