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. LINQ
  4. Row number in gridview using linq [Solved]

Row number in gridview using linq [Solved]

Scheduled Pinned Locked Moved LINQ
csharpcsslinqhelp
8 Posts 4 Posters 2 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.
  • K Offline
    K Offline
    kasraa00098000
    wrote on last edited by
    #1

    hi, im thinking about make row numbers in datagridview using linq extentions but i dont know how, currently i use {for statement} to make row numbers, when data in grid grow up to 10000 records then its really slow and its my problem , i just wanna make it quicker. ty

    N A 2 Replies Last reply
    0
    • K kasraa00098000

      hi, im thinking about make row numbers in datagridview using linq extentions but i dont know how, currently i use {for statement} to make row numbers, when data in grid grow up to 10000 records then its really slow and its my problem , i just wanna make it quicker. ty

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      What do you mean row numbers? You want to a row number to the display? Is this Windows or web? Perhaps if you showed a little of the code we could make suggestions for improvement


      I know the language. I've read a book. - _Madmatt

      K 1 Reply Last reply
      0
      • N Not Active

        What do you mean row numbers? You want to a row number to the display? Is this Windows or web? Perhaps if you showed a little of the code we could make suggestions for improvement


        I know the language. I've read a book. - _Madmatt

        K Offline
        K Offline
        kasraa00098000
        wrote on last edited by
        #3

        thanks for ur answer. this is the current code for(int i=0;i < dg.RowCount;i++) { dg.Rows[i].Cells[0].Value= i.ToString(); }

        1 Reply Last reply
        0
        • K kasraa00098000

          hi, im thinking about make row numbers in datagridview using linq extentions but i dont know how, currently i use {for statement} to make row numbers, when data in grid grow up to 10000 records then its really slow and its my problem , i just wanna make it quicker. ty

          A Offline
          A Offline
          Anurag Gandhi
          wrote on last edited by
          #4

          You can simply use the GridView Property.

          asp:TemplateField
          <ItemTemplate>
          <%# Container.DataItemIndex + 1 %>
          </ItemTemplate>
          </asp:TemplateField>

          I don't feel that linq is really needed here. But still if wish to do it using linq, use project and add rowNumber in your datasource.

          Anurag Gandhi.
          http://www.gandhisoft.com
          Life is a computer program and every one is the programmer of his own life.

          P 1 Reply Last reply
          0
          • A Anurag Gandhi

            You can simply use the GridView Property.

            asp:TemplateField
            <ItemTemplate>
            <%# Container.DataItemIndex + 1 %>
            </ItemTemplate>
            </asp:TemplateField>

            I don't feel that linq is really needed here. But still if wish to do it using linq, use project and add rowNumber in your datasource.

            Anurag Gandhi.
            http://www.gandhisoft.com
            Life is a computer program and every one is the programmer of his own life.

            P Offline
            P Offline
            PunkIsNotDead
            wrote on last edited by
            #5

            This shouldn't be at LINQ message board! :omg: if your paging is 10, maybe you can use

            <ItemTemplate>
            <%#String.Format("{0:000}", (((GridViewRow)Container).RowIndex + 1) + (GV_Resumen.PageIndex * 10))%>
            </ItemTemplate>
            <ItemStyle Width="2%" />

            K 1 Reply Last reply
            0
            • P PunkIsNotDead

              This shouldn't be at LINQ message board! :omg: if your paging is 10, maybe you can use

              <ItemTemplate>
              <%#String.Format("{0:000}", (((GridViewRow)Container).RowIndex + 1) + (GV_Resumen.PageIndex * 10))%>
              </ItemTemplate>
              <ItemStyle Width="2%" />

              K Offline
              K Offline
              kasraa00098000
              wrote on last edited by
              #6

              OOOPs! in windows application case there is no template item and so, guys im looking for row numbering in win app using linq extention. ty

              P 1 Reply Last reply
              0
              • K kasraa00098000

                OOOPs! in windows application case there is no template item and so, guys im looking for row numbering in win app using linq extention. ty

                P Offline
                P Offline
                PunkIsNotDead
                wrote on last edited by
                #7

                try adding a superficial column! but with a dataTable...

                var s = from N in Cnn.Datos.COM_TBL_Noticias
                select N;
                DataTable dt = new DataTable();
                int i = 0;
                dt.Columns.Add("Num", System.Type.GetType("System.Int32"));
                dt.Columns.Add("EncabezadoNoticia", System.Type.GetType("System.String"));
                dt.Columns.Add("DescripcionNoticia", System.Type.GetType("System.String"));
                dt.Columns.Add("FechaNoticia", System.Type.GetType("System.DateTime"));
                foreach (var lista in s)
                {
                dt.Rows.Add(i, lista.EncabezadoNoticia, lista.DescripcionNoticia, lista.FechaNoticia);
                i++;
                }
                DGV_Datos.DataSource = dt;

                and num would be the based 0 num! xD :-D

                K 1 Reply Last reply
                0
                • P PunkIsNotDead

                  try adding a superficial column! but with a dataTable...

                  var s = from N in Cnn.Datos.COM_TBL_Noticias
                  select N;
                  DataTable dt = new DataTable();
                  int i = 0;
                  dt.Columns.Add("Num", System.Type.GetType("System.Int32"));
                  dt.Columns.Add("EncabezadoNoticia", System.Type.GetType("System.String"));
                  dt.Columns.Add("DescripcionNoticia", System.Type.GetType("System.String"));
                  dt.Columns.Add("FechaNoticia", System.Type.GetType("System.DateTime"));
                  foreach (var lista in s)
                  {
                  dt.Rows.Add(i, lista.EncabezadoNoticia, lista.DescripcionNoticia, lista.FechaNoticia);
                  i++;
                  }
                  DGV_Datos.DataSource = dt;

                  and num would be the based 0 num! xD :-D

                  K Offline
                  K Offline
                  kasraa00098000
                  wrote on last edited by
                  #8

                  thank you! is there any way to put numbers directly in grid or table column? foreach has a long delay!

                  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