Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / DataGrid / May 2004

Tip: Looking for answers? Try searching our database.

Show DataGrid Item Count?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Allen Davis - 30 Apr 2004 14:41 GMT
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] - 05 May 2004 06:54 GMT
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

> 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?
Carlos CR - 05 May 2004 10:29 GMT
> 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
Allen Davis - 05 May 2004 15:01 GMT
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" <Allen.Davis@flex-n-gate.com> wrote in message
    news:01240070-18B0-404C-A67B-2A5642924ED1@microsoft.com...
    > 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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.