Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ObjectDataSource Call MaxRowCount multiple times

Reply
Thread Tools

ObjectDataSource Call MaxRowCount multiple times

 
 
tshad
Guest
Posts: n/a
 
      02-06-2010
If you have an ObjectDataSource and are using it to do the Page Count - it
calls a method that querys the database to get this number.

The problem is that everytime the user presses the page control at the
bottom of the grid to get the next page or another page, it calls this
method again.

<asp:ObjectDataSource ID="ObjectDataSource1" EnablePaging="true"
runat="server" SelectCountMethod="GetRowCount"
SelectMethod="BindControl" TypeName="DAO"
StartRowIndexParameterName="startRowIndex"
MaximumRowsParameterName="maximumRows">
</asp:ObjectDataSource>

In this case it calls SelectCountMethod (GetRowCount) each time a user wants
a new page.

In my DAO object, my method looks like:

public int GetRowCount()
{
// int id;

SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["ConnectString"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("GetDetailsRowCount", con);
com.CommandType = CommandType.StoredProcedure;

SqlDataReader dr = com.ExecuteReader();
int count = 0;
while (dr.Read())
{
if (dr["NumberOfRows"] != null)
int.TryParse(dr["NumberOfRows"].ToString(), out count);
}
return count;
}

The problem is that this method is called from the ObjectDataSource each
time a user wants a new page which means a new trip to the database to get
the number I already got the first time around.

You can't seem to store the number in the object as the DAO object is
created each time you get the next page.

Is there a way to tell the ODS to use the same number it had the first time
around?

Thanks,

Tom


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
str.Template 4 times slower than calling replace multiple times Jack Steven Python 2 03-09-2009 05:38 AM
Forms Authentication Fails some times and not some times??? =?Utf-8?B?bWF2cmlja18xMDE=?= ASP .Net 0 03-28-2006 10:48 PM
SetAuthCookie works some times and fails some times? =?Utf-8?B?bWF2cmlja18xMDE=?= ASP .Net 0 03-23-2006 09:24 PM
ObjectDataSource method as another ObjectDataSource David Thielen ASP .Net Web Controls 3 03-23-2006 01:50 AM
Why is the Constructor called 4 times but the Destructor 5 times? djskrill C++ 9 10-01-2003 07:18 PM



Advertisments