How to save items uploaded to the repeater?

I am loading a set of records that are loaded in a Repeater control. I have a CheckBox control for each record that determines whether the item is active / inactive. How do I scroll through all the entries in the Repeater when a button is clicked and save the state of the CheckBox ? I will need to get the record ID and the status of the "Verified" control.

Thanks!

+6
repeater
source share
1 answer

There are several ways to approach it. If you don’t re-bind the data to the PostBack (for example, rely on a repeater already filled in), you need to write the record identifier in some field that will be stored in ViewState. In this example, I used HiddenField :

 void Button_Click(object sender, EventArgs e) { foreach(RepeaterItem item in myRepeater.Items) { CheckBox cbxIsActive = item.FindControl("cbxID") as CheckBox; HiddenField hdfID = item.FindControl("recordID") as HiddenField; if(cbxIsActive != null && hdfID != null) { string recordID = hdfID.Value; bool isActive = cbxIsActive.Checked; UpdateRecord(recordID, isActive); } } } 
+17
source share

All Articles