Professional Web Applications Themes

total record count in datagrid - ASP.NET Data Grid Control

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 ...

  1. #1

    Default total record count in datagrid

    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 Guest

  2. #2

    Default Re: total record count in datagrid

    After you populate the DataSet do:

    Response.Write(myDataSet1.Tables("CommunitiesT1"). Rows.Count)

    That ought to do the trick! :-)

    Happy Programming!


    --

    Scott Mitchell
    [email]mitchell4guysfromrolla.com[/email]
    [url]http://www.4GuysFromRolla.com[/url]
    [url]http://www.ASPFAQs.com[/url]
    [url]http://www.ASPMessageboard.com[/url]

    * When you think ASP, think 4GuysFromRolla.com!



    DC Gringo wrote:
    > 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
    Scott Mitchell [MVP] Guest

Similar Threads

  1. Getting Total Item Count in Paging Datagrid
    By jason smith in forum ASP.NET Data Grid Control
    Replies: 6
    Last Post: October 28th, 07:26 PM
  2. Verity total doent count
    By Tom Jordahl in forum Coldfusion Server Administration
    Replies: 0
    Last Post: May 17th, 02:27 PM
  3. ASP Group Same Records and Give Total Count
    By gotcha in forum ASP Database
    Replies: 1
    Last Post: August 6th, 08:50 PM
  4. Any serverscript to count total images in a folder
    By sraval in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 10th, 05:00 AM
  5. Stop adding record in subform after record count = 1
    By Charlie in forum Microsoft Access
    Replies: 0
    Last Post: July 31st, 10:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139