views:

337

answers:

2

I am using ASP.Net 2.0. I am using a gridview component over some data because I wanted to get the paging functionality it provides. The rest of my site where I do not need to provide paging because I have used an alphabetical index or because the result set is small enough to fit in the screen I use a repeater. In the repeater I have added the delete shortcut to the end of the table in its own cell. The edit link is provided by clicking on any row in the results and that takes you to a new screen where you can edit the details.

I have not been able to find a way to move the edit and delete columns to the end. Is there perhaps a property that I missed or is the easiest way of doing this going to be extending the Gridview component. If that is the case would it better to extend the component or try and write my own paging functionality to acompany my repeater.

A: 

The best solution of them all would be to get the paging capablilities into your data access solution, so that if you need page 3 you only get those ten records and not the entire list. That way you could also use a repeater to render the list, without having to extend it with paging capabilities - just add another repeater at the bottom that loops out the page numbers as links.

However, if this is not possible, the easiest way would probably be to manually configure the GridView to render the way you want it to (or as close as possible...). It's been a while since I worked with a GridView, but the names I show below are at least close enough for you to find the correct ones with Intellisense in VS.

First, set

AutoGenerateColumns = False

on your GridView. Then, add a <Columns></Columns> section betweeen the <asp:GridView></asp:GridView> tags. Within that section, you should be able to specify each field you want to render, and the order you want them in.

Tomas Lycken
+2  A: 

Rather than using the autogenerate delete and edit buttons, you can manually add an edit and delete field using the 'Edit Columns' dialogue from the gridView smart tag. Make sure that Auto Generate fields is not selected and you can then add your columns as desired, and edit, delete and insert are all available as children of the CommandField option.

Macros