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); } } }
Rex m
source share