ObjectDataSource Call MaxRowCount multiple times

Discussion in 'ASP .Net' started by tshad, Feb 6, 2010.

  1. tshad

    tshad Guest

    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
    tshad, Feb 6, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWF2cmlja18xMDE=?=

    SetAuthCookie works some times and fails some times?

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 23, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    500
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 23, 2006
  2. =?Utf-8?B?bWF2cmlja18xMDE=?=

    Forms Authentication Fails some times and not some times???

    =?Utf-8?B?bWF2cmlja18xMDE=?=, Mar 28, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    484
    =?Utf-8?B?bWF2cmlja18xMDE=?=
    Mar 28, 2006
  3. djskrill
    Replies:
    9
    Views:
    689
    djskrill
    Oct 1, 2003
  4. Jack Steven
    Replies:
    2
    Views:
    418
    Chris Rebert
    Mar 9, 2009
  5. David Thielen

    ObjectDataSource method as another ObjectDataSource

    David Thielen, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    228
    Steven Cheng[MSFT]
    Mar 23, 2006
Loading...

Share This Page