Thanks for tdavisjr's input,
Hi Aussie,
As tdavisjr has mentioned, the ASP.NET Dropdownlist control is quite
different from the winform dropdownlist(this also applies to other controls
exists in both winform and ASP.NET). Actually this diference is due to the
underlying infrastructure and programming model. As for ASP.NET
Dropdownlist, it supports the following means to populate items:
1. statically declare the dropdownlist items in aspx template e.g.
=========
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>aaa</asp:ListItem>
<asp:ListItem>bbb</asp:ListItem>
<asp:ListItem>ccc</asp:ListItem>
</asp:DropDownList>
==========
2. Manualy create ListItem and add it into DropdownList.Items collection.
e.g:
=========
dim item1 as ListItem = new ListItem("item1", "item1")
dim item2 as ListItem= new ListItem("item2", "item2")
DropDownList1.Items.Add(item1)
DropDownList1.Items.Add(item2)
=========
3. populate the dropdownlist through databinding, supply a datasource and
which property (from the datasource record) to bound with the dropdownlist
item's property. e.g.
================
#CategoryClass has two public properties(ID and Name)
dim categories(5) as new CategoryClass;
// initlizing the categories array
DropDownList1.DataTextField= "Name"
DropDownList1.DataValueField = "ID"
DropDownList1.DataSource = categories
DropDownList1.DataBind()
==================
The following msdn reference has mentioned binding a dropdownlist with
datasource control(for ASP.NET 2.0):
#DropDownList Web Server Control Declarative Syntax
http://msdn2.microsoft.com/en-us/library/0dzka5sf.aspx
For your scenario, after you've added items into DropDownList, we can only
access them through the "Items" collection also, and the object in the
collection is of "ListItem" type(we can not convert it to our own custom
class type). The ListItem class have two public properties(Text and Value)
which are the two ones most useful to us. Also, you can access the current
selected Item in the DropDownList control through its "SelectedItem"
property.
In addition, the databinding in ASP.NET web page is quite different from
winform databinding, you can have a look at the following articles:
#Web Forms Data Binding
http://msdn.microsoft.com/library/en...rmsdatabinding.
asp?frame=true
#ASP.NET data binding overview
http://support.microsoft.com/kb/307860/en-us
If you have any more specific questions or problems, you can also provide
us some further code logic or background info so that we can have a look
and provid some further suggestions.
Hope this helps you a little.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial
response from the community or a Microsoft Support Engineer within 1
business day is
acceptable. Please note that each follow up response may take approximately
2 business days
as the support professional working with you may need further investigation
to reach the
most efficient resolution. The offering is not appropriate for situations
that require
urgent, real-time or phone-based interactions or complex project analysis
and dump analysis
issues. Issues of this nature are best handled working with a dedicated
Microsoft Support
Engineer by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.