Shuffling rows in a GridView

J

justin

One of the gridviews i'm using now apparently needs to have the added
functionality of re-arranging the order of the records it's
representing. These records have a priority field which the dataset
gets sorted on and I thought the quickest way to do this would be to
add "move up", "move down" buttons next to the grid which would shuffle
the rows up and down by swapping their priority field values and
updating.

At least that seemed to be the quickest way before I spent a day
pouring through documentation trying to find a way to get at the
dataset of the gridview with no success whatsoever. Thing's locked up
tighter than a duck's. Is there any way on God's green earth to access
the data of a gridview? Or is there a better way to do this, you see it
all the time with listboxes I'd hoped I could get the gridview to play
along...
 
A

Alvin Bruney [MVP]

I don't believe this is built in simply because row order is not usually an
overriding concern. But's it's really easy to do. Just re-order the
datasource, dataview, or dataset and rebind.

On second thought, if you need flexibility in row ordering, you should be
using a listbox and not a gridview.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
 
J

justin

Thanks for the reply Alvin,
Yes a listbox would be a far more clever solution but the existing page
uses the gridview's edit functionality so I can't really change it to a
listbox. And you're right, you just have to re-order the dataset. I
just can't find any way to prise that dataset out of the gridview, or
the objectdatasource that i'm using for it. There doesn't seem to be
any way to get to it.
I don't believe this is built in simply because row order is not usually an
overriding concern. But's it's really easy to do. Just re-order the
datasource, dataview, or dataset and rebind.

On second thought, if you need flexibility in row ordering, you should be
using a listbox and not a gridview.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


justin said:
One of the gridviews i'm using now apparently needs to have the added
functionality of re-arranging the order of the records it's
representing. These records have a priority field which the dataset
gets sorted on and I thought the quickest way to do this would be to
add "move up", "move down" buttons next to the grid which would shuffle
the rows up and down by swapping their priority field values and
updating.

At least that seemed to be the quickest way before I spent a day
pouring through documentation trying to find a way to get at the
dataset of the gridview with no success whatsoever. Thing's locked up
tighter than a duck's. Is there any way on God's green earth to access
the data of a gridview? Or is there a better way to do this, you see it
all the time with listboxes I'd hoped I could get the gridview to play
along...
 
A

Alvin Bruney [MVP]

I think you can get more specialized help for this in the www.asp.net forum.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


justin said:
Thanks for the reply Alvin,
Yes a listbox would be a far more clever solution but the existing page
uses the gridview's edit functionality so I can't really change it to a
listbox. And you're right, you just have to re-order the dataset. I
just can't find any way to prise that dataset out of the gridview, or
the objectdatasource that i'm using for it. There doesn't seem to be
any way to get to it.
I don't believe this is built in simply because row order is not usually
an
overriding concern. But's it's really easy to do. Just re-order the
datasource, dataview, or dataset and rebind.

On second thought, if you need flexibility in row ordering, you should be
using a listbox and not a gridview.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


justin said:
One of the gridviews i'm using now apparently needs to have the added
functionality of re-arranging the order of the records it's
representing. These records have a priority field which the dataset
gets sorted on and I thought the quickest way to do this would be to
add "move up", "move down" buttons next to the grid which would shuffle
the rows up and down by swapping their priority field values and
updating.

At least that seemed to be the quickest way before I spent a day
pouring through documentation trying to find a way to get at the
dataset of the gridview with no success whatsoever. Thing's locked up
tighter than a duck's. Is there any way on God's green earth to access
the data of a gridview? Or is there a better way to do this, you see it
all the time with listboxes I'd hoped I could get the gridview to play
along...
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top