SUN
SUN

Reputation: 973

put checkboxlist selectedvalue in string in asp.net

I have checkboxlist in which Item of checkbox & it's value is different. I need to show users item but when it gets submitted it should take selectedItems value. How it can be done?

string selectedProducts = string.Empty;
foreach (ListItem chk in productsList.Items) {
    if (chk.Selected == true) {
        selectedProducts += chk.Text + ", ";
    }
}

With above code I am getting selectedItem. How can I get selectedItems values?

Upvotes: 0

Views: 250

Answers (1)

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14624

You need to use Value property.

string selectedProducts = string.Empty;
foreach (ListItem chk in productsList.Items) {
    if (chk.Selected == true) {
        selectedProducts += chk.Value+ ", ";
    }
}

Upvotes: 1

Related Questions