binding datasource to dropdownlist control

D

DesignerX

I am being sent an ArrayList of ListItems.

I can bind to a dropdownlist control using:

oDropDownList.DataSource = oArrayList

This works but when the dropdownlist is rendered both the select box value
and the text are the same (The ListItem.Text), How do I get the
ListItem.Text to render as the text and the ListItem.Value to be the html
select option 'value'?

Thank You,
Stan
 
S

Saravana

Use DataTextField and DataValueField properties of dropdownlist to assign
text and value for dropdownlist.
 
D

DesignerX

Saravana,

Thanks for the reply, unfortunately that is my problem... I do not know how
to use the DataValueField property without looping thru the entire
ArrayList. With an ArrayList of ListItems, how would I use the
DataValueField to refer property to refer to a property of the object within
the array?

Thanks,
Stan
 
Joined
Dec 29, 2008
Messages
3
Reaction score
0
a sample code for u DesignerX

DropDownList1.DataValueField = dtCategoriesList.Columns["categoryID"].ColumnName.ToString();
DropDownList1.DataTextField = dtCategoriesList.Columns["categoryName"].ColumnName.ToString();
DropDownList1.DataBind();


__________________
HemaRitchie
realchennai.com/hema
 
Joined
Dec 29, 2008
Messages
3
Reaction score
0
oops!! add one more line b4 the above mentioned code

a sample code for u DesignerX

DropDownList1.DataSource = dtCategoriesList;


__________________
HemaRitchie
realchennai.com/hema
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top