Connecting Tech Pros Worldwide Forums | Help | Site Map

Dynamically adding content to selection list in ASP.NET / VB.NET

EEEdiot
Guest
 
Posts: n/a
#1: Nov 18 '05
Okay,

I know to add content dynamically to web page file you can have
something like the following and it would add a whole bunch of <option>
items for the <select> list. How do you dynamically add <optgroup> items
and <options> under them?

TIA!

In ASPX file:
<%@ Page Language="VB" inherits="..." Src="... .vb" AutoEventWireup="False"
%>
....
<select style="WIDTH: 155px" id="lst_Currency" runat="server"></select>
....

In VB file:

Imports ...

Public Class ...

Public Sub Page_Load(sender as Object, e as EventArgs) _
Handles MyBase.Load

If Me.IsPostBack = False
lst_Currency.Items.Add(New ListItem("Euros", "0.6075"))
lst_Currency.Items.Add(New ListItem("Japanese Yen",
"79.7894"))
lst_Currency.Items.Add(New ListItem("US Dollars", "0.7344"))
lst_Currency.Items.Add(New ListItem("Lower Slobovian
Dinars", "733.4939"))
End If
End Sub
End Class



avnrao
Guest
 
Posts: n/a
#2: Nov 18 '05

re: Dynamically adding content to selection list in ASP.NET / VB.NET


default DropDownList doesnt support this.
you can write your custom control to do this which just writes out the
required html.

you can see the difficulty to implement it in DropDownList here
http://weblogs.asp.net/asmith/archiv.../30/29846.aspx

Av.
"EEEdiot" <EEEdiot@hotmail.com> wrote in message
news:ic6dnVlfwpAtd0TdRVn2hA@giganews.com...[color=blue]
> Okay,
>
> I know to add content dynamically to web page file you can have
> something like the following and it would add a whole bunch of <option>
> items for the <select> list. How do you dynamically add <optgroup> items
> and <options> under them?
>
> TIA!
>
> In ASPX file:
> <%@ Page Language="VB" inherits="..." Src="... .vb"
> AutoEventWireup="False"
> %>
> ...
> <select style="WIDTH: 155px" id="lst_Currency" runat="server"></select>
> ...
>
> In VB file:
>
> Imports ...
>
> Public Class ...
>
> Public Sub Page_Load(sender as Object, e as EventArgs) _
> Handles MyBase.Load
>
> If Me.IsPostBack = False
> lst_Currency.Items.Add(New ListItem("Euros", "0.6075"))
> lst_Currency.Items.Add(New ListItem("Japanese Yen",
> "79.7894"))
> lst_Currency.Items.Add(New ListItem("US Dollars",
> "0.7344"))
> lst_Currency.Items.Add(New ListItem("Lower Slobovian
> Dinars", "733.4939"))
> End If
> End Sub
> End Class
>
>[/color]


EEEdiot
Guest
 
Posts: n/a
#3: Nov 18 '05

re: Dynamically adding content to selection list in ASP.NET / VB.NET


At least, I know.

"avnrao" <avn@newsgroups.com> wrote in message
news:Ou9oCIfWEHA.4032@TK2MSFTNGP11.phx.gbl...[color=blue]
> default DropDownList doesnt support this.
> you can write your custom control to do this which just writes out the
> required html.
>
> you can see the difficulty to implement it in DropDownList here
> http://weblogs.asp.net/asmith/archiv.../30/29846.aspx
>
> Av.
> "EEEdiot" <EEEdiot@hotmail.com> wrote in message
> news:ic6dnVlfwpAtd0TdRVn2hA@giganews.com...[color=green]
> > Okay,
> >
> > I know to add content dynamically to web page file you can have
> > something like the following and it would add a whole bunch of <option>
> > items for the <select> list. How do you dynamically add <optgroup>[/color][/color]
items[color=blue][color=green]
> > and <options> under them?
> >
> > TIA!
> >
> > In ASPX file:
> > <%@ Page Language="VB" inherits="..." Src="... .vb"
> > AutoEventWireup="False"
> > %>
> > ...
> > <select style="WIDTH: 155px" id="lst_Currency" runat="server"></select>
> > ...
> >
> > In VB file:
> >
> > Imports ...
> >
> > Public Class ...
> >
> > Public Sub Page_Load(sender as Object, e as EventArgs) _
> > Handles MyBase.Load
> >
> > If Me.IsPostBack = False
> > lst_Currency.Items.Add(New ListItem("Euros", "0.6075"))
> > lst_Currency.Items.Add(New ListItem("Japanese Yen",
> > "79.7894"))
> > lst_Currency.Items.Add(New ListItem("US Dollars",
> > "0.7344"))
> > lst_Currency.Items.Add(New ListItem("Lower Slobovian
> > Dinars", "733.4939"))
> > End If
> > End Sub
> > End Class
> >
> >[/color]
>
>[/color]


Closed Thread