I have a listview with multiple columns. One of the columns is a checkbox, another is a label. There are other columns but they’re not really relevant to this issue. In the click event of a button on this page I want to read the value of the label if the checkbox adjacent to it is selected. How do I read the label contents?
The code I have so far is included below. The code runs but the checked status of the checkboxes is never found to be checked. I checked the itemTemplate to confirm the name and ensure this problem wasn’t the result of a typo.
CheckBox chkSelected;
List<int> selectedIds = new List<int>();
foreach (var x in lvPeople.Items)
{
chkSelected = (CheckBox)x.FindControl("IsAlumni");
if (chkSelected.Checked)
{
int id = (int)lvPeople.DataKeys[x.DisplayIndex].Value;
selectedIds.Add(id);
}
}
You’d have something like this:
For example, in the selected item event you could have this code: