User107

User107

  • NA
  • 28
  • 17.8k

Is it possible to display selected items in dropdowncheckbox

Sep 16 2016 1:44 AM
In asp.net web application, i have dropdowncheckboxes control in that whatever items i selected i need to show that selected items in  dropdown textfield as separated with comma.
 
I tried this code but i am not getting result:
 
protected void dropdown1_SelectedIndexChanged(object sender, EventArgs e)
{
List<String> checkedList = new List<string>();
foreach (ListItem item in dropdown1.Items)
{
if (item.Selected)
{
checkedList.Add(item.Text);
}
dropdown1.DataTextField = String.Join(",", checkedList);
}
}
 My screen shots for this:
in My dropdown1 has many items i need to select two items i.e., shown in below figure
 
what i select items from dropdown it will display on text field as like below figure
 
 
Can anyone please tell me how to do this.
thank you

Answers (2)