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 total number of rows

Gridview total number of rows

Scheduled Pinned Locked Moved ASP.NET
10 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.
  • S Offline
    S Offline
    srinandan
    wrote on last edited by
    #1

    Hi all, I need to get the total number of records into GridView outside the any event of gridview. If I use GridView1.Rows.Count, then it just returns me the total number of rows on the page. But if I have, 5 pages having 10 records per page and 45 records total, Rows.Count will return me 10 on the first 4 pages, and 5, on the last page. But I need to get total number of record without using the gridview1's datasource like dataset or dataview etc. I need to use only n only gridview1 property. Thanks, Sri...

    A 1 Reply Last reply
    0
    • S srinandan

      Hi all, I need to get the total number of records into GridView outside the any event of gridview. If I use GridView1.Rows.Count, then it just returns me the total number of rows on the page. But if I have, 5 pages having 10 records per page and 45 records total, Rows.Count will return me 10 on the first 4 pages, and 5, on the last page. But I need to get total number of record without using the gridview1's datasource like dataset or dataview etc. I need to use only n only gridview1 property. Thanks, Sri...

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Then why you are not counting the Rows of your DataSource ?

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      S 1 Reply Last reply
      0
      • A Abhijit Jana

        Then why you are not counting the Rows of your DataSource ?

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

        S Offline
        S Offline
        srinandan
        wrote on last edited by
        #3

        Thanks Abhijit, This one is an interview question as per interviewer I have only the gridview to get the total number of rows. I know we find same using the Datasource of gridview. But i don't have this option. I have to use only n only gridview Thanks, Sri...

        A N 2 Replies Last reply
        0
        • S srinandan

          Thanks Abhijit, This one is an interview question as per interviewer I have only the gridview to get the total number of rows. I know we find same using the Datasource of gridview. But i don't have this option. I have to use only n only gridview Thanks, Sri...

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4

          Have a look into this , Total Row Count of GridView[^]

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          S 1 Reply Last reply
          0
          • S srinandan

            Thanks Abhijit, This one is an interview question as per interviewer I have only the gridview to get the total number of rows. I know we find same using the Datasource of gridview. But i don't have this option. I have to use only n only gridview Thanks, Sri...

            N Offline
            N Offline
            Nishant Singh
            wrote on last edited by
            #5

            Suppose GridView is gr

            int k=gr.PageSize*(gr.PageCount-1);
            gr.Currentpage=gr.PageCount-1;
            int p=gr.Rows.Count ;
            int GridRows= k+p;

            Try this I think you could get with a minor modification

            S 1 Reply Last reply
            0
            • A Abhijit Jana

              Have a look into this , Total Row Count of GridView[^]

              Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

              S Offline
              S Offline
              srinandan
              wrote on last edited by
              #6

              I am doing the following thing protected void Button1_Click(object sender, EventArgs e) { int recordCount; DataSet ds=(DataSet)GridView1.DataSource; recordCount = ds.Tables[0].Rows.Count; Response.Write(recordCount); } get error "Object reference not set to an instance of an object." stating ds.Tables[0] is null. I am not getting why this is happing even i am binding the gridview in page load under if(!IsPostBack). Thanks, Sri...

              1 Reply Last reply
              0
              • N Nishant Singh

                Suppose GridView is gr

                int k=gr.PageSize*(gr.PageCount-1);
                gr.Currentpage=gr.PageCount-1;
                int p=gr.Rows.Count ;
                int GridRows= k+p;

                Try this I think you could get with a minor modification

                S Offline
                S Offline
                srinandan
                wrote on last edited by
                #7

                Thanks Nishant, You code is fine but we need to find the number of rows in the page of gridview to calculate the total number of rows in grid view. Any idea to find the number of rows in the last page?? Thanks, Sri...

                S 1 Reply Last reply
                0
                • S srinandan

                  Thanks Nishant, You code is fine but we need to find the number of rows in the page of gridview to calculate the total number of rows in grid view. Any idea to find the number of rows in the last page?? Thanks, Sri...

                  S Offline
                  S Offline
                  Satish Mahapatra
                  wrote on last edited by
                  #8

                  Can you try with the paging to false and then check the recordcount after that u can make the paging as true.

                  S 1 Reply Last reply
                  0
                  • S Satish Mahapatra

                    Can you try with the paging to false and then check the recordcount after that u can make the paging as true.

                    S Offline
                    S Offline
                    srinandan
                    wrote on last edited by
                    #9

                    Hi Prasant, I am doing the following things: protected void Button1_Click(object sender, EventArgs e) { GridView1.AllowPaging = false; Response.Write(GridView1.PageCount.ToString()); GridView1.AllowPaging = true; } Still getting 10 rows as rows on current page. Thanks, Sri...

                    N 1 Reply Last reply
                    0
                    • S srinandan

                      Hi Prasant, I am doing the following things: protected void Button1_Click(object sender, EventArgs e) { GridView1.AllowPaging = false; Response.Write(GridView1.PageCount.ToString()); GridView1.AllowPaging = true; } Still getting 10 rows as rows on current page. Thanks, Sri...

                      N Offline
                      N Offline
                      Nishant Singh
                      wrote on last edited by
                      #10

                      Hi Srinandan, Set the page count to Last page

                      gr.CurrentPageIndex=gr.PageCount-1;
                      gr.Rows.Count

                      You will get the rows on the last page .

                      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