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. Sr no in Datagrid

Sr no in Datagrid

Scheduled Pinned Locked Moved ASP.NET
tutorial
5 Posts 4 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
    miniThomas
    wrote on last edited by
    #1

    I want to show on Column called Sr No in my datagrid. At runtim this column will show values like 1,2,3.... for each selected row based on the records available in dataset. How to acheive this!!!!!!! Thanks, Mini Thomas

    A A K 3 Replies Last reply
    0
    • M miniThomas

      I want to show on Column called Sr No in my datagrid. At runtim this column will show values like 1,2,3.... for each selected row based on the records available in dataset. How to acheive this!!!!!!! Thanks, Mini Thomas

      A Offline
      A Offline
      Arvind Srivastava
      wrote on last edited by
      #2

      you can create an Autoincrement column and seed by 1 and bind with sr. no column. Be :) Bye

      1 Reply Last reply
      0
      • M miniThomas

        I want to show on Column called Sr No in my datagrid. At runtim this column will show values like 1,2,3.... for each selected row based on the records available in dataset. How to acheive this!!!!!!! Thanks, Mini Thomas

        A Offline
        A Offline
        aaraaayen 0
        wrote on last edited by
        #3

        hi, here is the code to display Sr No. in datagrid. In the following code loadDs is dataset. if (loadDs.Tables.Count > 0) { loadConsultant.Tables[0].Columns.Add(new DataColumn("Sl_NO", System.Type.GetType("System.String"))); foreach (DataTable table in loadConsultant.Tables) { int i = 1; foreach (DataRow row in table.Rows) { foreach (DataColumn column in table.Columns) { row["Sl_NO"] = i.ToString(); } i = i + 1; } } } Regards,

        Prya

        M 1 Reply Last reply
        0
        • M miniThomas

          I want to show on Column called Sr No in my datagrid. At runtim this column will show values like 1,2,3.... for each selected row based on the records available in dataset. How to acheive this!!!!!!! Thanks, Mini Thomas

          K Offline
          K Offline
          Kapil Thakur
          wrote on last edited by
          #4

          hi, Use the autoincrement column as told by arvind rather than looping through the dataset. using autoiuncrement column is more efficient than going through loops. thanks, Kapil Thakur (Where's there is Kapil , there is a way)

          1 Reply Last reply
          0
          • A aaraaayen 0

            hi, here is the code to display Sr No. in datagrid. In the following code loadDs is dataset. if (loadDs.Tables.Count > 0) { loadConsultant.Tables[0].Columns.Add(new DataColumn("Sl_NO", System.Type.GetType("System.String"))); foreach (DataTable table in loadConsultant.Tables) { int i = 1; foreach (DataRow row in table.Rows) { foreach (DataColumn column in table.Columns) { row["Sl_NO"] = i.ToString(); } i = i + 1; } } } Regards,

            Prya

            M Offline
            M Offline
            miniThomas
            wrote on last edited by
            #5

            Hello Prya, In ur code how do I bind the row with Datagrid also there is error on line foreach (DataColumn column in table.Columns) { can u help mi out Thanks, Mini Thomas

            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