total record count in datagrid

Discussion in 'ASP .Net' started by DC Gringo, Mar 4, 2004.

  1. DC Gringo

    DC Gringo Guest

    I have a datagrid control that has paging set up and working. What I would
    like is a total record count (not just per page) in the header or near the
    header of the datagrid.

    Here's my code:

    <asp:DataGrid
    AllowCustomPaging="false"
    AllowPaging="true"
    AllowSorting="true"
    AlternatingItemStyle-BackColor="#EFEFEF"
    AutoGenerateColumns="false"
    Border="0"
    Cellpadding="4"
    Cellspacing="0"
    CssClass="DataGrid"
    DataKeyField="clnGUID"
    Enabled="true"
    EnableViewState="true"
    HeaderStyle-BackColor="Black"
    HeaderStyle-Font-Bold="True"
    HeaderStyle-ForeColor="White" id="DataGrid2" runat="server"
    ShowFooter="false"
    OnSortCommand="SortCommand_OnClick"
    OnPageIndexChanged="PageIndexChanged_OnClick"
    PageSize="50"
    PagerStyle-Mode="NumericPages"
    PagerStyle-HorizontalAlign="Right"
    ShowHeader="true"
    >




    Protected _sqlStmt As String = _
    "SELECT cols FROM tables"

    Sub Page_Load(Source As Object, E As EventArgs)
    If Not Page.IsPostBack Then
    BindData()
    End If
    End Sub

    Sub BindData()
    Dim conString As String = "server=server;database=db;uid=user;pwd=pwd;"

    Dim myDataSet1 As New DataSet
    Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString)
    myDataAdapter1.Fill(myDataSet1, "CommunitiesT1")
    DataGrid2.DataSource = myDataSet1.Tables("CommunitiesT1")


    DataGrid2.DataBind()


    End Sub
    --
    _____
    DC G
     
    DC Gringo, Mar 4, 2004
    #1
    1. Advertising

  2. DC Gringo

    Morgan Guest

    You could use the Rows.Count property off of your dataset table.
    myDataSet1.Tables("CommunitiesT1").Rows.Count

    HTH,

    Morgan
    "DC Gringo" <> wrote in message
    news:%...
    > I have a datagrid control that has paging set up and working. What I

    would
    > like is a total record count (not just per page) in the header or near the
    > header of the datagrid.
    >
    > Here's my code:
    >
    > <asp:DataGrid
    > AllowCustomPaging="false"
    > AllowPaging="true"
    > AllowSorting="true"
    > AlternatingItemStyle-BackColor="#EFEFEF"
    > AutoGenerateColumns="false"
    > Border="0"
    > Cellpadding="4"
    > Cellspacing="0"
    > CssClass="DataGrid"
    > DataKeyField="clnGUID"
    > Enabled="true"
    > EnableViewState="true"
    > HeaderStyle-BackColor="Black"
    > HeaderStyle-Font-Bold="True"
    > HeaderStyle-ForeColor="White" id="DataGrid2" runat="server"
    > ShowFooter="false"
    > OnSortCommand="SortCommand_OnClick"
    > OnPageIndexChanged="PageIndexChanged_OnClick"
    > PageSize="50"
    > PagerStyle-Mode="NumericPages"
    > PagerStyle-HorizontalAlign="Right"
    > ShowHeader="true"
    > >

    >
    >
    >
    > Protected _sqlStmt As String = _
    > "SELECT cols FROM tables"
    >
    > Sub Page_Load(Source As Object, E As EventArgs)
    > If Not Page.IsPostBack Then
    > BindData()
    > End If
    > End Sub
    >
    > Sub BindData()
    > Dim conString As String = "server=server;database=db;uid=user;pwd=pwd;"
    >
    > Dim myDataSet1 As New DataSet
    > Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString)
    > myDataAdapter1.Fill(myDataSet1, "CommunitiesT1")
    > DataGrid2.DataSource = myDataSet1.Tables("CommunitiesT1")
    >
    >
    > DataGrid2.DataBind()
    >
    >
    > End Sub
    > --
    > _____
    > DC G
    >
    >
     
    Morgan, Mar 4, 2004
    #2
    1. Advertising

  3. DC Gringo

    nfedin Guest

    Why not check your DataTable to see how many rows it has?

    i.e. RecordCount = myDataSet1.Tables("CommunitiesT1").Rows.Count

    This will give all the records being bound to the data grid.

    Neil

    "DC Gringo" <> wrote in message news:<#>...
    > I have a datagrid control that has paging set up and working. What I would
    > like is a total record count (not just per page) in the header or near the
    > header of the datagrid.
    >
    > Here's my code:
    >
    > <asp:DataGrid
    > AllowCustomPaging="false"
    > AllowPaging="true"
    > AllowSorting="true"
    > AlternatingItemStyle-BackColor="#EFEFEF"
    > AutoGenerateColumns="false"
    > Border="0"
    > Cellpadding="4"
    > Cellspacing="0"
    > CssClass="DataGrid"
    > DataKeyField="clnGUID"
    > Enabled="true"
    > EnableViewState="true"
    > HeaderStyle-BackColor="Black"
    > HeaderStyle-Font-Bold="True"
    > HeaderStyle-ForeColor="White" id="DataGrid2" runat="server"
    > ShowFooter="false"
    > OnSortCommand="SortCommand_OnClick"
    > OnPageIndexChanged="PageIndexChanged_OnClick"
    > PageSize="50"
    > PagerStyle-Mode="NumericPages"
    > PagerStyle-HorizontalAlign="Right"
    > ShowHeader="true"
    > >

    >
    >
    >
    > Protected _sqlStmt As String = _
    > "SELECT cols FROM tables"
    >
    > Sub Page_Load(Source As Object, E As EventArgs)
    > If Not Page.IsPostBack Then
    > BindData()
    > End If
    > End Sub
    >
    > Sub BindData()
    > Dim conString As String = "server=server;database=db;uid=user;pwd=pwd;"
    >
    > Dim myDataSet1 As New DataSet
    > Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString)
    > myDataAdapter1.Fill(myDataSet1, "CommunitiesT1")
    > DataGrid2.DataSource = myDataSet1.Tables("CommunitiesT1")
    >
    >
    > DataGrid2.DataBind()
    >
    >
    > End Sub
     
    nfedin, Mar 4, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KS
    Replies:
    6
    Views:
    594
    George
    Feb 2, 2004
  2. thomson
    Replies:
    1
    Views:
    828
    Brock Allen
    Jun 11, 2005
  3. JustinCarmony
    Replies:
    1
    Views:
    476
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Apr 2, 2007
  4. jason smith

    Getting Total Item Count in Paging Datagrid

    jason smith, Jul 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    281
    Alvin Bruney
    Jul 23, 2003
  5. DC Gringo

    total record count in datagrid

    DC Gringo, Mar 4, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    142
    DC Gringo
    Mar 4, 2004
Loading...

Share This Page