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. Gridview: How do I get the datafield of a boundcolumn in codebehind

Gridview: How do I get the datafield of a boundcolumn in codebehind

Scheduled Pinned Locked Moved ASP.NET
questiondatabaseannouncement
3 Posts 2 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
    Member 4382232
    wrote on last edited by
    #1

    Hi, I have a user control with a gridview control. In the RowUpdating event I raise an event caught in the page to do the update to the database. I want to get the datafield of each cell to know which field in the database to update. Another question related to this is that I've noticed that if I make AutogenerateColumns = true, the columns are not created in the same order than it is specified in the select query returned from the database. How can I make sure that the columns is bound in the same order as it is returned from the db?

    L 1 Reply Last reply
    0
    • M Member 4382232

      Hi, I have a user control with a gridview control. In the RowUpdating event I raise an event caught in the page to do the update to the database. I want to get the datafield of each cell to know which field in the database to update. Another question related to this is that I've noticed that if I make AutogenerateColumns = true, the columns are not created in the same order than it is specified in the select query returned from the database. How can I make sure that the columns is bound in the same order as it is returned from the db?

      L Offline
      L Offline
      Laddie
      wrote on last edited by
      #2
      1. Populate your datakey names. 2) Now you can access them in side RowUpdating by gridView1.DataKeyNames[e.RowIndex].Values[columnName] 1) Try adding a group by clause int he select query

      Thanks Laddie Kindly rate if the answer was helpful

      M 1 Reply Last reply
      0
      • L Laddie
        1. Populate your datakey names. 2) Now you can access them in side RowUpdating by gridView1.DataKeyNames[e.RowIndex].Values[columnName] 1) Try adding a group by clause int he select query

        Thanks Laddie Kindly rate if the answer was helpful

        M Offline
        M Offline
        Member 4382232
        wrote on last edited by
        #3

        I don't think I explained my problem clearly. First I want to know how to find the name of the datafield which the cell is bound to in each cell in a row, for ex. If the value in column[0] is "1234567" i want to get from code that the datafield is IDNumber, to be able to know which field in the db to update. The reason why I don't have this info available is because the grid is generic in a user control and I bind the grid to a list. Secondly I want to know how to specify the order of the columns returned and not the rows of data. I always thought it will databound the columns in the same order as the select query: for instance: Select IDNumber, suname, initials from Employee. When I bind the datasource: the first column is Initials, sencond column is surname and the last column is IDNumber. I don't understand why this happens, any idea? Thanx in advance

        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