Solved

How to bind a string array to a drop down list

Posted on 2010-11-20
5
316 Views
Last Modified: 2012-05-10
I need to bind and string array to a drop down list .
0
Comment
Question by:Ammar Iqbal
5 Comments
 
LVL 18

Expert Comment

by:Richard Lee
ID: 34179305
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
 
LVL 11

Accepted Solution

by:
SAMIR BHOGAYTA earned 500 total points
ID: 34179550
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34179552
                 array<String^>^ ar = {("one"), "two", "three"};
                  comboBox1->DataSource = ar;
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34179554
Oh, that is C++.net code - you posted into a C++.net area as well as C#

Did you require C# code ?
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 34179555
Yes I have done it already, Forgot to delte this question. Anyways I ma accepting your answer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now