Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > binding datasource to dropdownlist control

Reply
Thread Tools

binding datasource to dropdownlist control

 
 
DesignerX
Guest
Posts: n/a
 
      07-21-2003
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


 
Reply With Quote
 
 
 
 
Saravana
Guest
Posts: n/a
 
      07-22-2003
Use DataTextField and DataValueField properties of dropdownlist to assign
text and value for dropdownlist.

--
Saravana
Microsoft India Community Star,
MCAD,SE,SD,DBA.


"DesignerX" <> wrote in message
news:fL-...
> 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
>
>



 
Reply With Quote
 
 
 
 
DesignerX
Guest
Posts: n/a
 
      07-22-2003
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

"Saravana" <> wrote in message
news:...
> Use DataTextField and DataValueField properties of dropdownlist to assign
> text and value for dropdownlist.
>
> --
> Saravana
> Microsoft India Community Star,
> MCAD,SE,SD,DBA.
>
>
> "DesignerX" <> wrote in message
> news:fL-...
> > 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
> >
> >

>
>



 
Reply With Quote
 
HemaRitchie HemaRitchie is offline
Junior Member
Join Date: Dec 2008
Posts: 3
 
      12-29-2008
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
 
Reply With Quote
 
HemaRitchie HemaRitchie is offline
Junior Member
Join Date: Dec 2008
Posts: 3
 
      12-29-2008
oops!! add one more line b4 the above mentioned code

a sample code for u DesignerX

DropDownList1.DataSource = dtCategoriesList;


__________________
HemaRitchie
realchennai.com/hema
 
Reply With Quote
 
HemaRitchie HemaRitchie is offline
Junior Member
Join Date: Dec 2008
Posts: 3
 
      12-29-2008
happy coding
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DropDownList Binding to LINQ DataSource John Padilla ASP .Net Web Controls 0 12-15-2007 07:08 PM
Update Dropdownlist datasource on bound control jkeel@charter.net ASP .Net 1 04-06-2007 02:03 AM
Binding multiple Datasource to DropDownlist Mr Not So Know It All ASP .Net 0 01-03-2007 11:01 PM
Binding to JNDI datasource - please help John Chambers Java 1 03-21-2005 11:50 PM
binding xml as datasource suzy ASP .Net 0 04-11-2004 05:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57