Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
3
Reply
show selected items as comma separated in multi dropdown
User107
8 years ago
347
Reply
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
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
How do I change the column header of a GridView into 2 rows?
[URGENT] Unable to launch asp.net web application