Why does my datagrid.databind blow up?

Discussion in 'ASP .Net Web Controls' started by carlor, Oct 14, 2005.

  1. carlor

    carlor Guest

    Hi there,

    I'm at a loss to resolve this so I'm hoping someone can enlighten me.

    I have a search user control that contains and displays a results user
    control if files are found. If any results are found, I set the results UC
    datatable property to the results datatable, set the results datagrid's
    datasource to the dataTable and perform a dataBind. That works fine.

    I am using paging on the dataGrid and that works. The problem I'm running
    into is when I perform another find after changing pages on the dataGrid.
    Let's say my first result set produced 5 pages of results and I select and
    display the 3rd page. I then perform another find which produces a result set
    of only 1 page. The results UC is still there so I set the UC's dataTable
    property to the new results set, set the dataGrid's dataSource to the new
    dataTable (because this is a postback the dataSource is nothing) and perform
    a dataBind.

    This is where it blows up. Because the dataGrid's CurrentPageIndex is set to
    the 3rd page but the new result set only has 1 page, I get the following
    exception:

    "Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount."

    Am I missing something painfully obvious? Any idea how I resolve this problem?


    Thanks a bunch,

    Carlo.
     
    carlor, Oct 14, 2005
    #1
    1. Advertising

  2. Set the CurrentPageIndex to 0 when you execute a new search because the
    databind by itself does not reset that variable.
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "carlor" wrote:

    > Hi there,
    >
    > I'm at a loss to resolve this so I'm hoping someone can enlighten me.
    >
    > I have a search user control that contains and displays a results user
    > control if files are found. If any results are found, I set the results UC
    > datatable property to the results datatable, set the results datagrid's
    > datasource to the dataTable and perform a dataBind. That works fine.
    >
    > I am using paging on the dataGrid and that works. The problem I'm running
    > into is when I perform another find after changing pages on the dataGrid.
    > Let's say my first result set produced 5 pages of results and I select and
    > display the 3rd page. I then perform another find which produces a result set
    > of only 1 page. The results UC is still there so I set the UC's dataTable
    > property to the new results set, set the dataGrid's dataSource to the new
    > dataTable (because this is a postback the dataSource is nothing) and perform
    > a dataBind.
    >
    > This is where it blows up. Because the dataGrid's CurrentPageIndex is set to
    > the 3rd page but the new result set only has 1 page, I get the following
    > exception:
    >
    > "Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount."
    >
    > Am I missing something painfully obvious? Any idea how I resolve this problem?
    >
    >
    > Thanks a bunch,
    >
    > Carlo.
    >
     
    Phillip Williams, Oct 14, 2005
    #2
    1. Advertising

  3. carlor

    carlor Guest

    Thanks! That works but is there a "cleaner" solution?

    Carlo.

    "Phillip Williams" wrote:

    > Set the CurrentPageIndex to 0 when you execute a new search because the
    > databind by itself does not reset that variable.
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "carlor" wrote:
    >
    > > Hi there,
    > >
    > > I'm at a loss to resolve this so I'm hoping someone can enlighten me.
    > >
    > > I have a search user control that contains and displays a results user
    > > control if files are found. If any results are found, I set the results UC
    > > datatable property to the results datatable, set the results datagrid's
    > > datasource to the dataTable and perform a dataBind. That works fine.
    > >
    > > I am using paging on the dataGrid and that works. The problem I'm running
    > > into is when I perform another find after changing pages on the dataGrid.
    > > Let's say my first result set produced 5 pages of results and I select and
    > > display the 3rd page. I then perform another find which produces a result set
    > > of only 1 page. The results UC is still there so I set the UC's dataTable
    > > property to the new results set, set the dataGrid's dataSource to the new
    > > dataTable (because this is a postback the dataSource is nothing) and perform
    > > a dataBind.
    > >
    > > This is where it blows up. Because the dataGrid's CurrentPageIndex is set to
    > > the 3rd page but the new result set only has 1 page, I get the following
    > > exception:
    > >
    > > "Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount."
    > >
    > > Am I missing something painfully obvious? Any idea how I resolve this problem?
    > >
    > >
    > > Thanks a bunch,
    > >
    > > Carlo.
    > >
     
    carlor, Oct 14, 2005
    #3
  4. No.
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "carlor" wrote:

    > Thanks! That works but is there a "cleaner" solution?
    >
    > Carlo.
    >
    > "Phillip Williams" wrote:
    >
    > > Set the CurrentPageIndex to 0 when you execute a new search because the
    > > databind by itself does not reset that variable.
    > > --
    > > HTH,
    > > Phillip Williams
    > > http://www.societopia.net
    > > http://www.webswapp.com
    > >
    > >
    > > "carlor" wrote:
    > >
    > > > Hi there,
    > > >
    > > > I'm at a loss to resolve this so I'm hoping someone can enlighten me.
    > > >
    > > > I have a search user control that contains and displays a results user
    > > > control if files are found. If any results are found, I set the results UC
    > > > datatable property to the results datatable, set the results datagrid's
    > > > datasource to the dataTable and perform a dataBind. That works fine.
    > > >
    > > > I am using paging on the dataGrid and that works. The problem I'm running
    > > > into is when I perform another find after changing pages on the dataGrid.
    > > > Let's say my first result set produced 5 pages of results and I select and
    > > > display the 3rd page. I then perform another find which produces a result set
    > > > of only 1 page. The results UC is still there so I set the UC's dataTable
    > > > property to the new results set, set the dataGrid's dataSource to the new
    > > > dataTable (because this is a postback the dataSource is nothing) and perform
    > > > a dataBind.
    > > >
    > > > This is where it blows up. Because the dataGrid's CurrentPageIndex is set to
    > > > the 3rd page but the new result set only has 1 page, I get the following
    > > > exception:
    > > >
    > > > "Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount."
    > > >
    > > > Am I missing something painfully obvious? Any idea how I resolve this problem?
    > > >
    > > >
    > > > Thanks a bunch,
    > > >
    > > > Carlo.
    > > >
     
    Phillip Williams, Oct 14, 2005
    #4
    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. Simon Wittber

    python memory blow out

    Simon Wittber, Jan 27, 2005, in forum: Python
    Replies:
    1
    Views:
    312
    Istvan Albert
    Jan 27, 2005
  2. Stephen Thorne

    Re: python memory blow out

    Stephen Thorne, Jan 27, 2005, in forum: Python
    Replies:
    1
    Views:
    301
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,003
    Smokey Grindel
    Dec 2, 2006
  4. Midex
    Replies:
    24
    Views:
    922
  5. Michael
    Replies:
    0
    Views:
    227
    Michael
    Dec 29, 2003
Loading...

Share This Page