Repeater databinding problems - page events, repeaters and buttons

Posted on 2005-02-24
Medium Priority
Last Modified: 2012-08-13
I'm having a huge problem trying to do something that I thought would be simple. I've got a Repeater, which lists a number of items along with a checkbox besides each.

What should happen is:

- User checks the items to be deleted
- Presses the button
- Checked items are removed from the database
- Page reflects the changes in the underlying data and then allows further selection

The problem is that once the button is pressed the Repeater's contents aren't refreshing. I presume this is because:

When the button is pressed:

- The page reloads
- The Page_Init event fires (this is where I'm doing the databinding)
- The button event fires, which updates the database

This means that the Repeater contains old data.

I've tried rebinding during the PreRender event and in the button event code, but it doesn't seem to help.

What am I doing wrong?
Question by:tjrobinson
  • 2
  • 2

Expert Comment

ID: 13391804
Hello. Sorry for my poor english.

I didn´t test, but I guess the Page_Init event occurs before the ViewState data is assigned to the webcontrols.

1 - You bind the initial data from the database. This data goes to the viewstate.
2 - You check the lines to be deleted in the repeater and click in the remove button.
3 - You make your databind in the Page_Init.
2 - If the Repeater has the property EnableViewState = True, then it will populate the repeater with the old data in the viewstate.

I sugest you try to bind your data in the Page_Load. Is there any problem with this method?


Author Comment

ID: 13391872
The problem with binding in Page_Load, is that it loses the viewstate information for the checkboxes, so when the event handler for the button is triggered, none of the boxes are ticked.

Expert Comment

ID: 13391913
Can you... delete the lines in the Page_Init and bind the new data in the Page_Load?
LVL 16

Accepted Solution

RobertRFreeman earned 2000 total points
ID: 13395254
In the button event, rebind.  The update should also refresh the dataset, if not, then clear and refill.

Author Comment

ID: 13402194
Thanks, I'd not thought of clearing the dataset. It didn't solve the problem straight away but made me rethink what I was doing and it now works fine.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question