SarahX
SarahX

Reputation: 61

How to set Previous/Next record by click an asp.net button

I have a Listview binded with a ObjectDataScource and a div to display a record's details on a page. Outside the Listview and div I have Previous/Next buttons on the same page. I want to click the button to display Previous/Next buttons in the Div. How can this be done? I use onItemcommand to trigge each record to be deplayed in Div.

Upvotes: 0

Views: 2674

Answers (2)

SarahX
SarahX

Reputation: 61

I have tried to solve this problem for some days. There are many ways to do so but in my situation, all seems doen't work, untill I found Listview.selectedDataKey. You can set as many as possible paremeters for property DataKey of Listview. For example DataKey="ProductID,ProductName,SentDate,TrustID". Then in Next/Previous onclick event, you get selectedIndex for current selected item, then set selectedIndex as +1 for next item and -1 for previous item. then you can get data through selectedDataKey[0],[1]... You do what you want to do in onclick event for previous/next item.

Upvotes: 1

David
David

Reputation: 73594

MyListView.SelectedIndex = MyListView.SelectedIndex + 1;

or

MyListView.SelectedIndex = MyListView.SelectedIndex + 1;

Of course, you'll need to check to ensure that you're not going outside the bounds of the ListView or you're get an error.... So when incrementing ensure that you're not going past MyListView.Items.Count, and when decrementing, ensure that your current index is > 0.

Upvotes: 0

Related Questions