How to bind a string array to a drop down list

I need to bind and string array to a drop down list .
LVL 1
Ammar IqbalSenior IT Consultant/senior Software engineerAsked:
Who is Participating?
 
SAMIR BHOGAYTAConnect With a Mentor Freelancer and IT ConsultantCommented:
Hello, You have to try this code

string[] myStrings = new string[] {"string1", "string2", "string3"};

DropDownList ddl = new DropDownList();

ddl = (DropDownList)e.Row.FindControl("ddlMyStrings");

ddl.DataSource = myStrings;

ddl.DataBind();
0
 
Richard LeeSoftware EnthusiastCommented:
Just bind as normal. The string becomes the value and the text.

<asp:DropDownList ID="ddlList" runat="server" />

DaTribe
List<string> items = new List<string>
	{"One", "Two", "Three"};

ddlList.DataSource = items;
ddlList.DataBind();

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
                 array<String^>^ ar = {("one"), "two", "three"};
                  comboBox1->DataSource = ar;
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Oh, that is C++.net code - you posted into a C++.net area as well as C#

Did you require C# code ?
0
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
Yes I have done it already, Forgot to delte this question. Anyways I ma accepting your answer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.