Help adding a "rank" column to a sortable GridView

R

rusmo1

I have a GridvVew in which all of the columns are sortable. I want the
first column to display the position of the row in the sorted order
regardless of which column I've sorted or which direction it is
currently sorted. This "rank" column should always display like so:
1
2
3
4
5
etc...

Programmatically, the problem I'm having is that the value of row[row
number x][column number y] needs to change each time the table is
sorted. I'm starting with a DataTable filled by a database query, if
that helps. I feel like there should be an easy way to do this but I
haven't run across it anywhere.

Thanks in advance for any suggestions!
Will.
 
O

Onwuka Emeka

You can add this to your gridview :

<asp:TemplateField>

<ItemTemplate><%#(int)DataBinder.Eval(Container,"RowIndex") + 1
%></ItemTemplate>

</asp:TemplateField>
 
B

Budd

Onwuka Emeka said:
You can add this to your gridview :

<asp:TemplateField>

<ItemTemplate><%#(int)DataBinder.Eval(Container,"RowIndex") + 1
%></ItemTemplate>

</asp:TemplateField>

I have a GridvVew in which all of the columns are sortable. I want the
first column to display the position of the row in the sorted order
regardless of which column I've sorted or which direction it is
currently sorted. This "rank" column should always display like so:
1
2
3
4
5
etc...

Programmatically, the problem I'm having is that the value of row[row
number x][column number y] needs to change each time the table is
sorted. I'm starting with a DataTable filled by a database query, if
that helps. I feel like there should be an easy way to do this but I
haven't run across it anywhere.

Thanks in advance for any suggestions!
Will.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top