User107

User107

  • NA
  • 28
  • 17.6k

show selected items as comma separated in multi dropdown

Sep 15 2016 4:55 AM
How can i show the selected items as comma separated in the Multi select dropdown text field in asp.net
 
In my web application, i am trying to do show the selected items as comma separated in the Multi select drop down text field is it possible to do and how can i do this can any one tell me.

I tried:

protected void dropdown1_SelectedIndexChanged(object sender, EventArgs e)
{
string element= string.Empty;
foreach(ListItem item in dropdown1.Items)
{
if (item.Selected)
element += "'" + item.Value + "',";
}
if (element.Length > 0)
{
element = element.Substring(0, element.Length - 1);
string qry = "select * from Selections where col1= '" + dropdowncol1.SelectedValue.ToString() + "' and col2 in (" + element+ ")";
SqlCommand cmd = new SqlCommand(qry, con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dropdown1.DataTextField = element;

}

Can anyone help me to how to do this.
Thank you 
 
 

Answers (3)