?
Solved

Repeater databinding problems - page events, repeaters and buttons

Posted on 2005-02-24
5
Medium Priority
?
320 Views
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?
0
Comment
Question by:tjrobinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Noturno
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?

Regards,
Noturno
0
 

Author Comment

by:tjrobinson
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.
0
 
LVL 1

Expert Comment

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

Accepted Solution

by:
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.
0
 

Author Comment

by:tjrobinson
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.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

770 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