Save the checked status of a CheckBox included inside an ASP ListView

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

Answers


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).


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.


Need Your Help

How to bind the Unique Ids of Computer System into Software

windows winforms hash registry licensing

I have a Windows Stand Alone Application software that i need to be password protected.For this i have hashed the unique ids of the system and put into the License text file of the Application fold...

Universal audio player with controls in multiple view controllers

ios objective-c cocoa-touch

Audioboo iOS app has a universal audio player with controls (i.e. play/pause button.) view always visible on loaded view controllers when playing content. Also sometimes the view controllers themse...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.