473,513 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Load DropDownList

Hello,

I have a list of entities (with properties Key and Description).

Which is the best manner of load dropdownlist with this list ?

Thanks in advance
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net

Apr 24 '07 #1
4 5675
The best manner is to databind the ddl to the list like this:

myDdl.DataSource = myList;
myDdl.DataTextField = "Description";
myDdl.DataValueField = "Key";
myDdl.DataBind();

You can do the same in the markup.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Alhambra Eidos Kiquenet" <Al*******************@discussions.microsoft.com >
wrote in message news:D7**********************************@microsof t.com...
Hello,

I have a list of entities (with properties Key and Description).

Which is the best manner of load dropdownlist with this list ?

Thanks in advance
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net

Apr 24 '07 #2
Assuming you have the list in the form of array/datatable/arraylist:

DropDown.DataSource = <entity collection>;
DropDown.DataTextField = <entity property name for text display
(description)>;
DropDown.DataValueField = <entity property name for value (key)>;
DropDown.DataBind ();

"Alhambra Eidos Kiquenet" wrote:
Hello,

I have a list of entities (with properties Key and Description).

Which is the best manner of load dropdownlist with this list ?

Thanks in advance
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net
Apr 24 '07 #3
I'd try but it appears the following error:

Data source is an invalid type. It must be either an IListSource,
IEnumerable, or IDataSource.

My List of entities is a Dictionary<int, MyEntityObject>.
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net

"Siva M" wrote:
Assuming you have the list in the form of array/datatable/arraylist:

DropDown.DataSource = <entity collection>;
DropDown.DataTextField = <entity property name for text display
(description)>;
DropDown.DataValueField = <entity property name for value (key)>;
DropDown.DataBind ();

"Alhambra Eidos Kiquenet" wrote:
Hello,

I have a list of entities (with properties Key and Description).

Which is the best manner of load dropdownlist with this list ?

Thanks in advance
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net
Apr 24 '07 #4
Assign DataSource property to Dictionary.Values, which has the desired
collection having your entities.

"Alhambra Eidos Kiquenet" wrote:
I'd try but it appears the following error:

Data source is an invalid type. It must be either an IListSource,
IEnumerable, or IDataSource.

My List of entities is a Dictionary<int, MyEntityObject>.
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net

"Siva M" wrote:
Assuming you have the list in the form of array/datatable/arraylist:

DropDown.DataSource = <entity collection>;
DropDown.DataTextField = <entity property name for text display
(description)>;
DropDown.DataValueField = <entity property name for value (key)>;
DropDown.DataBind ();

"Alhambra Eidos Kiquenet" wrote:
Hello,
>
I have a list of entities (with properties Key and Description).
>
Which is the best manner of load dropdownlist with this list ?
>
Thanks in advance
--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net
>
Apr 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2761
by: Stanley J Mroczek | last post by:
How do you load a dropdownlist when edit is clicked in a datagrid ? <Columns> <asp:BoundColumn DataField="OptionDescription" ItemStyle-Wrap="True" HeaderText="Option...
3
828
by: Stanley J Mroczek | last post by:
I am trying to load a droplist in VB when the edit is clicked in a datagrid. I tried to use OnDataBinding and loading the droplist in subroutine "loaddd". I get this error Object reference not set...
1
1787
by: Stanley J Mroczek | last post by:
I am trying to load a dropdownlist in VB when the edit is clicked in a datagrid. How do i call Sub loaddd to load the dropdownlist <asp:TemplateColumn runat="server" HeaderText="Id Type Option"...
9
21628
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
18
2423
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a...
0
990
by: Jim in Arizona | last post by:
When the page loads, a dropdownlist is populated from a table. I populate the DataTextField with a persons name, and the DataValueField with the ID of the table (the key field) for further...
2
6926
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.