• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

How to bind a string array to a drop down list

I need to bind and string array to a drop down list .
Ammar Iqbal
Ammar Iqbal
1 Solution
Richard LeeSoftware EnthusiastCommented:
Just bind as normal. The string becomes the value and the text.

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

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

ddlList.DataSource = items;

Open in new window

SAMIR BHOGAYTAFreelancer 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;

AndyAinscowFreelance programmer / ConsultantCommented:
                 array<String^>^ ar = {("one"), "two", "three"};
                  comboBox1->DataSource = ar;
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 ?
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
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.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now