[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

GridView - Change row order

Experts,

I have a GridView that is bound to a table in my database that uses a column for row order but I don't want the users to just plug in a number to that columns data. What I want is up and down arrows in each row that will move the order for that row up and down accordingly. I know that this can be brute forced but I am looking for a nice, slick and simple way of doing this ... suggestions?

Thanks in advance,

Wally Atkins
0
dfu23
Asked:
dfu23
  • 4
  • 2
1 Solution
 
rodmjayCommented:
Maybe some sort of arbrirary index column in the database.  When you want to move the item up or down you can then swap the index number with the next in line and then rebind.  I have never worked out this solution, this is just the first idea that came to my head.
0
 
dfu23Author Commented:
how do i find out what row the image that was clicked was in?
0
 
dfu23Author Commented:
oh ... as an FYI,

I am using images to display the up and down buttons <asp:imagebutton>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rodmjayCommented:
well, you can set the datakey property of the datagrid, so I am assuming you can do something like this (i dont have vs in front of me)

<columns>
<templatecolumn>
  <asp:imagebutton runat=server commandname="up" ...
  <asp:imagebutton runat=server commandname="down" ...
</templatecolumn>
</columns>

And from this point the row_command should hook the events of the row.  You will need to reference the datakey (or db id) from this row, and there should be some way to get the columnindex of the current row.  From here you should be able to get the datakey of the above (columnindex -1) or below (columnindex +1).  This would be the approach i take.  You may have to look on msdn for exact implementation of the datakeys if you have never done it, but it is definately doable.  If you are having problems from here let me know and well see if we cant dig a little deeper into details.
0
 
dfu23Author Commented:
Thanks rodmjay ...

That method did the trick. I thought that there might be a simpler way to do this with new functionality in the GridView vs the DataGrid. The link that I posted above also was very key in getting the index of the row where the imagebutton was clicked.

Thanks very much for your responses.

Wally Atkins
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now