IMG-LOGO

How to get selected checkboxlist items values in ASP.Net C#?

andy - 28 Jul, 2013 17682 Views 0 Comment

You may wonder how you can get the values of selected checkboxes in C#. Well it is pretty easy, in this tutorial, we will show how you can get those values.

Let's assume yo checkboxlist control is named "chkItems"

To get the value you can use the following c# scripts.

// we create a temporary string to store the selected values
string values = "";

// We perform a for loop to check if each checkbox is selected then we get the value
foreach (ListItem objItem in chkItems.Items) {
	if (objItem.Selected) {
		values += objItem.Value + ",";
	}
}

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Articles

How to remove html tags from string in c#?

Sometimes you need to remove HTML tags from string to ensure there are no dangerous or malicious scripts especially when you want to store the string or data text into the database.