Show DataGrid Item Count?

A

Allen Davis

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?
 
S

Saravana [MVP]

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 said:
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?
 
C

Carlos CR

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
 
A

Allen Davis

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 said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top