Get selected value in Checkboxlist

Hello Everybody,

Yesterday I was facing a problem getting the current value of the checkboxlist.

I have tried using the selected value, as I thought that would give me the current value of the checkbox, but it appears to be giving me the first value that is selected all the time.

I have also tried to use the selectedItem property, but that does the same as I would expect, because the property says it get the item with the lowest value.

After searching i came up with the solution which is below...
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)
         value = CheckBoxList1.Items[index].Value; 


Twitter Delicious Facebook Digg Stumbleupon Favorites More