Question

I know there are similar questions about this issue (for example, here and here) but no one results helpful for my problem.

I have a ListView control showing all the users registered in the database and there is a CheckBox for each user shown if the user is approved or not, and I wanna save the changes directly when the CheckBox's Checked property changes.

I know it's not correct to add the event handler on the ListView_ItemDataBound, because after the CheckBox's AutoPostback there is not a new binding, thus the event handler get lost. On the other hand, I can't append the method directly on the ASPX file because this way I can't know which user is affected by the change (at least, I think I can't).

Any sugestion?

Thanks a lot

Was it helpful?

Solution

You have a couple of options.

It's possible that the ListView.ItemCommand event might fire. I'm not sure, though, because the documentation just specifies buttons. You might want to experiment.

The other option would be to harness the ListView.ItemCreated command. I believe that this always runs, regardless of whether the ListView is bound or not, because the item always has to be created, even if it's from ViewState. What you would do in the event handler for that event would be to attach an event handler to the CheckBox Click or CheckChanged event (I forget what the server-side name is for a CheckBox state change event).

OTHER TIPS

So i ran into the same problem. i'm curious, on your page load are you checking if its a postback?

if(!Post.IsPostBack){
//normal page load
}

If you don't have that check, it will call your page load logic, in my case it was resetting the checkbox everytime with my data object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top