Solved

How to bind a string array to a drop down list

Posted on 2010-11-20
5
318 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Obtain cell value using column ID in DataGrid using VB.NET 2 25
tableview is not updating 1 21
bound data table problem 2 33
ASP.NET Content Page 3 31
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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …

830 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