Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Row Number in GridView?

Row Number in GridView?

Scheduled Pinned Locked Moved ASP.NET
databasealgorithmssalesquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark Tutt
    wrote on last edited by
    #1

    I've been searching for a while for a way to implement what sounded like a simple customer request. Some of their forms have gridviews on them, and they would simply like a row number in each row. I could change the stored procedure around a bit to generate a row number column, but it seems like there should be an easier way... I've probably been working too long at this point and should just sleep on it, but if someone could give me a quick pointer it would be appreciated!

    M 1 Reply Last reply
    0
    • M Mark Tutt

      I've been searching for a while for a way to implement what sounded like a simple customer request. Some of their forms have gridviews on them, and they would simply like a row number in each row. I could change the stored procedure around a bit to generate a row number column, but it seems like there should be an easier way... I've probably been working too long at this point and should just sleep on it, but if someone could give me a quick pointer it would be appreciated!

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi Mark, The RowIndex[^] property will give you the row number of each GridViewRow, and this is the zero-based value:

      asp:TemplateField
      <ItemTemplate>
      <%# ((GridViewRow)Container).RowIndex%>
      </ItemTemplate>
      </asp:TemplateField>

      R 1 Reply Last reply
      0
      • M minhpc_bk

        Hi Mark, The RowIndex[^] property will give you the row number of each GridViewRow, and this is the zero-based value:

        asp:TemplateField
        <ItemTemplate>
        <%# ((GridViewRow)Container).RowIndex%>
        </ItemTemplate>
        </asp:TemplateField>

        R Offline
        R Offline
        RichardGrimmer
        wrote on last edited by
        #3

        minhpc_bk wrote:

        The RowIndex[^] property will give you the row number of each GridViewRow, and this is the zero-based value:

        Header and footer need to be taken into accout too (if 2.0)..... if (gv.RowIndex==0) { //we have a header row } elseif (gv.RowIndex==1) { //footer } else { //"proper" row } "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

        M 1 Reply Last reply
        0
        • R RichardGrimmer

          minhpc_bk wrote:

          The RowIndex[^] property will give you the row number of each GridViewRow, and this is the zero-based value:

          Header and footer need to be taken into accout too (if 2.0)..... if (gv.RowIndex==0) { //we have a header row } elseif (gv.RowIndex==1) { //footer } else { //"proper" row } "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi there, In fact, the header and footer (also pager) are not included in the Rows collection of the GridView control, so the RowIndex property of those rows does not have meaning, and it's simply set to -1.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups