Creating an element in vb.net at run-time

  • Thread starter Thread starter Garg
  • Start date Start date
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);
 
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!
 
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

Back
Top