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. General Programming
  3. Visual Basic
  4. autogenerate column in datagridview in vb.net 2005

autogenerate column in datagridview in vb.net 2005

Scheduled Pinned Locked Moved Visual Basic
csharphelp
2 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.
  • P Offline
    P Offline
    pankajgarg12
    wrote on last edited by
    #1

    Sir/Madam, I have a table , having two fields , first for name and second for roll number.I don't have serial number field in that table.Can , I display Serial number field in the datagridview , with those two fields. I mean if i have ten records in the table. Then datagrid should display record no for each row, like for first row it should display 1 , and for second row , there should display 2 and so on.This should happen in the extra column in the datagridview.Is it possible. Please help. Thanks and regards Pankaj

    C 1 Reply Last reply
    0
    • P pankajgarg12

      Sir/Madam, I have a table , having two fields , first for name and second for roll number.I don't have serial number field in that table.Can , I display Serial number field in the datagridview , with those two fields. I mean if i have ten records in the table. Then datagrid should display record no for each row, like for first row it should display 1 , and for second row , there should display 2 and so on.This should happen in the extra column in the datagridview.Is it possible. Please help. Thanks and regards Pankaj

      C Offline
      C Offline
      coolestCoder
      wrote on last edited by
      #2

      Hi, You can use sql query in this case. If your current sql query is - select name,rollno from students Then modify the query as - select 0 as [Serial No.],name, rollno from students. This modified query will generate a column named Serial No. whoes rows will be filled by 0. Then in the program use a counter to count the rows, in the RowDataBound event handler. Replace the text in column 0 with the counter value. You will get your desired resutls. Hope i am clear enough. I am assuming that you are using SQL Server as database.


      "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


      coolestCoder

      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