Show DataGrid Item Count?

Discussion in 'ASP .Net Datagrid Control' started by Allen Davis, Apr 30, 2004.

  1. Allen Davis

    Allen Davis Guest

    I have a DataGrid in an ASP.NET page that is the third of three nested controls (2 DataLists and the DataGrid). It uses relations in the DataSet and a DataView RowFilter to determine what data to bind to and display. What I'd like to do is show a count of items in the DataGrid header but I can't find a method for this. Does anyone have any suggestions?
    Allen Davis, Apr 30, 2004
    #1
    1. Advertising

  2. You can calculate the count using datagrid.items. But datagrid items will
    include header,footer and pager. If you have any of these items, then
    substract these from datagrid.items. Then it will give you total number of
    items in that datagrid. I hope this should help you

    --
    Saravana
    Microsoft MVP - ASP.NET
    www.extremeexperts.com



    "Allen Davis" <> wrote in message
    news:...
    > I have a DataGrid in an ASP.NET page that is the third of three nested

    controls (2 DataLists and the DataGrid). It uses relations in the DataSet
    and a DataView RowFilter to determine what data to bind to and display. What
    I'd like to do is show a count of items in the DataGrid header but I can't
    find a method for this. Does anyone have any suggestions?
    Saravana [MVP], May 5, 2004
    #2
    1. Advertising

  3. Allen Davis

    Carlos CR Guest

    "Saravana [MVP]" <> wrote in
    news:uG#:

    > You can calculate the count using datagrid.items. But datagrid items
    > will include header,footer and pager. If you have any of these items,
    > then substract these from datagrid.items. Then it will give you total
    > number of items in that datagrid. I hope this should help you


    Or if you are using a DataView to fetch de DataGrid you can use
    DataView.Count.

    Hope it helps

    Carlos CR
    Carlos CR, May 5, 2004
    #3
  4. Allen Davis

    Allen Davis Guest

    Thanks, Saravana, Carlso. And, as Carlos suggested in his reply, I do have a function that uses the DataView to get the count as shown here

    Function PassengerCount(ByVal DataItem As Object) As Integer
    Dim drv As DataRowView = DataItem
    Dim intPassengers As Integer
    intPassengers = drv.DataView.Count()
    PassengerCount = intPassengers
    End Function

    Though I'm not certain that's the most efficient way to do it. But, because I'm using BoundColumns in the ASP.NET page, I can't call this function as the value of HeaderText for one of those BoundColumns. I can use GetChildRelation from the DataList one level above the DataGrids, get a count from the resulting DataView and display the results there. But I want to show the count with each DataGrid not just once in the containing DataList. But generating a DataView twice instead of once seems wasteful.

    Any thoughts about how to display the results in the header of the DataGrids?

    ----- Saravana [MVP] wrote: -----

    You can calculate the count using datagrid.items. But datagrid items will
    include header,footer and pager. If you have any of these items, then
    substract these from datagrid.items. Then it will give you total number of
    items in that datagrid. I hope this should help you

    --
    Saravana
    Microsoft MVP - ASP.NET
    www.extremeexperts.com



    "Allen Davis" <> wrote in message
    news:...
    > I have a DataGrid in an ASP.NET page that is the third of three nested

    controls (2 DataLists and the DataGrid). It uses relations in the DataSet
    and a DataView RowFilter to determine what data to bind to and display. What
    I'd like to do is show a count of items in the DataGrid header but I can't
    find a method for this. Does anyone have any suggestions?
    Allen Davis, May 5, 2004
    #4
    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. Praveen Balanagendra via .NET 247
    Replies:
    2
    Views:
    4,088
  2. efelnavarro09
    Replies:
    2
    Views:
    933
    efelnavarro09
    Jan 26, 2011
  3. jason smith

    Getting Total Item Count in Paging Datagrid

    jason smith, Jul 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    256
    Alvin Bruney
    Jul 23, 2003
  4. QUASAR
    Replies:
    6
    Views:
    418
    QUASAR
    Jan 17, 2004
  5. VBTECH

    e.Item.Cells.Count in UpdateCommand event of Datagrid

    VBTECH, Apr 21, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    253
    Brock Allen
    Apr 21, 2005
Loading...

Share This Page