datasource.recordcount? How to obtain this?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I (or is this even possible) get the total number of records from a
datasource control in ASP.NET 2.0?

I’ve messed around with getting the row count from the grid that the
datasource is bound to, but, that control uses paging and it appears that the
count is only for the page that is in view.

I’m guessing that this is pretty simple, but, I’m flummoxed.

Thanks for any help you can offer.

B
 
Phillip,
You blow my mind. Is there anything you don't know or haven't worked
with!?!

Thanks once again. The e.AffectedRows worked (at least so far). I tried
working with the other line of code, but, I must admit that I don't
understand the code constructiion. Should you have the time and inclination
to answer my followup I'd appreciate it, but, it is more curiosity for me at
this point rather than an urgent need. So...

My data grid is "GridVew1"
The code: ((GridView1)e.ReturnValue).Count doesn't work when I put it in the
Page_load event. My guess it that since I'm using. I'm don't think I
understand it enough to try to work with it too much. So...
What does this do? "( ).count" and what does this "(DataGrid)e.ReturnValue"
do?

Thanks as always for your straight to the point and spot on responses.

B
 
Phillip,
You blow my mind. Is there anything you don't know or haven't worked
with!?!

Thanks once again. The e.AffectedRows worked (at least so far). I tried
working with the other line of code, but, I must admit that I don't
understand the code constructiion. Should you have the time and inclination
to answer my followup I'd appreciate it, but, it is more curiosity for me at
this point rather than an urgent need. So...

My data grid is "GridVew1"
The code: ((GridView1)e.ReturnValue).Count doesn't work when I put it in the
Page_load event. My guess it that since I'm using. I'm don't think I
understand it enough to try to work with it too much. So...
What does this do? "( ).count" and what does this "(DataGrid)e.ReturnValue"
do?

Thanks as always for your straight to the point and spot on responses.

B
 
Depending on the type of DataSource object that you use the AffectedRows
property of the eventargs might work or not. For the
ObjectDataSourceStatusEventArgs it will work:
http://msdn2.microsoft.com/en-us/li...ctdatasourcestatuseventargs.affectedrows.aspx

For the SqlDataSourceEventArgs, it will work if you do not have this
DataSourceMode="DataReader" in the markup, otherwise you will get 0
http://msdn2.microsoft.com/en-us/li...qldatasourcestatuseventargs.affectedrows.aspx

Regarding your question:

The code: ((DataView)e.ReturnValue) was actually a typo. My apology. I
sort of relied on you viewing the demo. It should have been
(DataView)e.ReturnValue as in the demo link I provided. This code should not
be placed in the method that handles the Page.Load. Notice its place in the
demo whose link I gave to you:
http://www.webswapp.com/codesamples/aspnet20/dropdownlist_gridview/

void odsCustomersList_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
//notice that this datasource returns a DataView
lblCount1.Text = "Total Record count in the dropdownlist above= "
+ ((DataView)e.ReturnValue).Count.ToString();
}

The explanation for that construct is:
((DataView)e.ReturnValue).Count would cast the returned value of the object
datasource to a DataView then gets the record count from the DataView.

My apology for the typo that caused this confusion.
 
Sorry, you are correct. I should have checked out the demo first. Thanks
for clarifying the code. Makes sense.

Ignore my duplicate response, not sure how that happened.

Thanks!
B
 
Back
Top