How To Add Ranking To a GridView?

Last post 05-17-2008 1:44 AM by JZoerman. 1 replies.

Sort Posts:

  • How To Add Ranking To a GridView?

    05-16-2008, 11:35 PM
    • Loading...
    • Avarice
    • Joined on 08-27-2006, 7:10 PM
    • New Jersey
    • Posts 94

    I am using a GridView to display a list of the highest scores in a game.  I simply want to add the ranking of 1, 2, 3, 4 to a column in the GridView.  How can I do this?  I am having trouble with ROW_NUMBER() in SQL Server 2005 so I think I need to use .NET for this.

    You can't stop entropy so why even try?
  • Re: How To Add Ranking To a GridView?

    05-17-2008, 1:44 AM
    Answer
    • Loading...
    • JZoerman
    • Joined on 08-24-2006, 6:27 AM
    • Posts 128

    Here is a simple solution that may be suffice for you.

    Add a template field to the gridview control

    Add a label to the template field

    After databinding the gridview call the sub below

     Protected Sub RankGrid()
            Dim lblRank2 As Label
            Dim Rank As Integer = 0
            Dim e As GridViewRow

            For Each e In GridView1.Rows
                lblRank2 = CType(e.FindControl("lblRank"), Label)
                Rank += 1
                lblRank2.Text = Rank.ToString()
            Next
    End Sub

    Hope this helps...

Page 1 of 1 (2 items)