|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Row count for query through SqlDataSource and GridViewI'm using a GridView (for paging) and SqlDataSource on an ASP.NET 2.0 page.
Everything is working, but I cannot find a clean way to get the total number of results (like RowCount in a dataset). Right now I'm running the query a second time in a SqlDataAdapter, which I find really hack-ish. There must be a way to get the TOTAL number of rows in a result (not just the number of rows on this page). Thanks in Advance, Ryan You can get a record count if you handle the Selected event of the datasource
object that is bound to the GridView, e.g. void odsCustomersList_Selected(object sender, ObjectDataSourceStatusEventArgs e) { //notice that this datasource returns a DataView lblCount1.Text = "Total Record count = " + ((DataView)e.ReturnValue).Count.ToString(); } 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/library/system.web.ui.webcontrols.objectdatasourcestatuseventargs.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/library/system.web.ui.webcontrols.sqldatasourcestatuseventargs.affectedrows.aspx Show quoteHide quote "RyanRounkles" wrote: > I'm using a GridView (for paging) and SqlDataSource on an ASP.NET 2.0 page. > Everything is working, but I cannot find a clean way to get the total number > of results (like RowCount in a dataset). Right now I'm running the query a > second time in a SqlDataAdapter, which I find really hack-ish. There must be > a way to get the TOTAL number of rows in a result (not just the number of > rows on this page). > > Thanks in Advance, > > Ryan
C#/ASP.NET 2.0 - Convert HTML Table to DataGrid/Source
How to set property "ReadOnly" on all TextBoxes on a WebForm Composite Server Control and DefaultValue Attribute The case of the crazy reseting dropdowns :-( Please help! Looking for a book on writing ASP.NET Controls with VB.NET using ASPNET objects in custom webcontrol general request about links CompileWith From one form to another.. Indent Items in ASP:ListBox? |
|||||||||||||||||||||||