Creating an element in vb.net at run-time

G

Garg

Please tellme how do I write vb.net code for the following code:

var opt = document.createElement("option");
opt.text = j;
opt.value = j;
document.all(elementname).options.add(opt);
 
N

Nathan Sokalski

Try the following:


Dim j As String = "Your text and value"
Dim opt As New ListItem(j)
Me.DropDownList1.Items.Add(opt)


This technique will automatically set the Text and Value properties to the
same value. If you prefer, you can set the Text and Value properties using
one of the following techniques instead:


Dim opt As New ListItem()
opt.Text = "Your text"
opt.Value = "Your value"

Dim opt As New ListItem("Your text", "Your value")


Good Luck!
 
G

Garg

Try the following:

Dim j As String = "Your text and value"
Dim opt As New ListItem(j)
Me.DropDownList1.Items.Add(opt)

This technique will automatically set the Text and Value properties to the
same value. If you prefer, you can set the Text and Value properties using
one of the following techniques instead:

Dim opt As New ListItem()
opt.Text = "Your text"
opt.Value = "Your value"

Dim opt As New ListItem("Your text", "Your value")

Good Luck!
--
Nathan Sokalski
(e-mail address removed)://www.nathansokalski.com/







- Show quoted text -

thanks nathan!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top