Note that there are some explanatory texts on larger screens.

plurals
  1. POTotal Row Count SqlDataSource GridView
    primarykey
    data
    text
    <p>So I have a GridView set up to a SqlDataSource. Paging is enabled and I have a drop down menu that changes the number of rows displayed per page. I am able get the total of rows displayed in a single page but I want to show the total number of rows as well. (Like this: "Showing 1 - 25 of 315"). </p> <p>So, my questions are:</p> <p>1) How do I get the total number of rows for the entire DataSource? (not just GridView) The code I have, OnSelectedData method, does not work and returns a zero.</p> <p>2) How do I get the numbers to display differently for each page? For example, on the second page it needs to say "Showing 26 - 50 of 315"</p> <p>Here's my code (C#):</p> <pre><code>public partial class UserControls_BloombergAllUsersControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } int gridViewTotalRowCount; protected void onSelectedData(object sender, SqlDataSourceStatusEventArgs e) { gridViewTotalRowCount = e.AffectedRows; } protected void GridView1_DataBound(object sender, EventArgs e) { int pageRowsCount = GridView1.Rows.Count; Total1.Text = "Showing 1 - " + pageRowsCount.ToString() + " of " + gridViewTotalRowCount.ToString(); } private void BindGridView1() { try { this.GridView1.DataBind(); if (Convert.ToInt32(DropDownList1.SelectedValue) != null) GridView1.PageSize = Convert.ToInt32(DropDownList1.SelectedValue); } catch (Exception ex) { throw ex; } } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; BindGridView1(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { BindGridView1(); } </code></pre> <p>}</p> <p>If anyone could help that would be great. Thanks! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload