User-1072848465 posted
Is it possible to iteriate through ListViewDataItems to save changes to checkboxes in a ListView? My problem is when I modify the checkboxes the new values are not being passed to my code behind.
Here is my ListView ItemTemplate is is being populated by binding a list in code behind
<ItemTemplate>
<asp:CheckBox ID="standardChkBox" runat="server" Checked='<%# Convert.ToBoolean(Eval("Applied")) %>'Text='<%# Eval("Abbreviation") %>' />
</ItemTemplate>
Once the list is displayed on the page I need to have the ability for the user to modify the checkboxes and save them back to the table. I have an OnClick event on a button that calls this
protected void applyStandardsBtn_Click(object sender, EventArgs e)
{
foreach (ListViewDataItem item in StandardsListView.Items)
{
bool chkBox = false;
CheckBox checkselect = item.FindControl("standardChkBox") as CheckBox;
if (checkselect.Checked)
chkBox = true;
Byte bchkBox = Convert.ToByte(chkBox);
Label lblStandardId = item.FindControl("standID_lbl") as Label;
int iStandardID = Convert.ToInt32(lblStandardId.Text);
using (var context = new CurriculumModelContainer())
{
AppliedStandard s = context.AppliedStandards
.First(i => i.Id == iStandardID);
s.applied = bchkBox;
context.SaveChanges();
}
}
}
How can I retrieve the new values on the checkboxes?
Thanks!