Wednesday, August 03, 2011

How to get the latest selected Checkbox value from a checkbox list?

Posted by Rahul Kharde at 3:42 AM

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;

}

}



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top