Sometimes, you may need to find which latest checkbox item of your CheckboxList is selected. Normally ASP .NET CheckboxList does not allowed getting the latest value on SelectedIndexChanged. So if you want to have it, you have to add it yourself. In this post I 'm going to show you a simple way to get latest selected checkbox form the CheckboxList.
My Reference code as follows
First I prepared a checkbox list with some items. In this sample I have added some item manually but you can do this using Data Binding.
Code
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
string value = string.Empty;
string result = Request.Form["__EVENTTARGET"];
string[] checkedBox = result.Split('$');
int index = int.Parse(checkedBox[checkedBox.Length - 1]);
if (CheckBoxList1.Items[index].Selected)
{
Label1.Text = CheckBoxList1.Items[index].Value;
}
}
Comments
Post a Comment