ASP.NET ListView select and highlight line through checkbox

I am trying to get an ASP.NET 3.5 ListView control to select and highlight rows using checkboxes displayed in the first column. If I use asp: LinkButton instead of a checkbox, line selection is supported automatically via the LinkButton CommandName = Select property. How do I do this using a checkbox? And once I succeeded, how do I get the selected items when the submit button is clicked on the form?

+1


source to share


1 answer


I'm not sure if I'm following what you are trying to achieve, if you want a visual change when you check the box? If so, your best bet would be to use jQuery and attach this checkbox to the onchange event.

Then when you submit back the form you can iterate through the items in the ListView and check the checkbox, check its state and then do what you want:



foreach(var item in listView1.Items){
  var checkbox = (CheckBox)item.FindControl("checkBox1");
  if(checkbox.Checked) // do stuff
}

      

+1


source







All Articles