Dynamically generating content in a dropdown

garcon

Well-known member
Joined
Dec 13, 2004
Messages
47
Programming Experience
Beginner
Folks,

I'm attempting to dynamcially generate content in a dropdown. I'm having problems thopugh trying to figure it all out. Can you help me please?

--------------.aspx file------------------

HTML:
<asp:DropDownList id="DropDownList1" runat="server">
		<asp:ListItem Value="NS">Select currency of your card</asp:ListItem>
		<asp:ListItem Text="EUR"></asp:ListItem>
		<asp:ListItem Text="CAD"></asp:ListItem>
		<asp:ListItem Value="NL">Not Listed</asp:ListItem>
</asp:DropDownList>


----code-behind file: aspx.vb--------

VB.NET:
[/color][/size]
[size=2][color=#0000ff][size=2][color=#0000ff][/color][/size][/color][/size] 
[size=2][color=#0000ff][size=2][color=#0000ff]Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] DropDownList1_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] DropDownList1.Load
	DropDownList1.Items[0].add("?")???

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][/color][/size]

[size=2][color=#0000ff][size=2][color=#0000ff][/color][/size]



Thing is though I think I need to declare an array with the elements in it? Does anyone know how to do this exactly?

Thanks
G.
 
all you need is
VB.NET:
DropDownList1.Items.Add(*whatever goes here*)
I usually put it under form_load
 
Back
Top