ObjectDataSource Call MaxRowCount multiple times

T

tshad

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.ConnectionStrings["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
 

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