Pages

Tuesday, 31 January 2012

Adding Items to ListBox Control in ASP.NET

To add items to the collection,the following synatax can be usefull
        ListBox1.Items.Add(TextBox1.Text);
You can also add instances of the ListItem object to get different values for the item name and value
VB
    ListBox1.Items.Add(New ListItem("Olivine","MG2SI04"));
C#
    ListBox1.Items.Add(New ListItem("Olivine","MG2SI04"));
The example adds a new instance of the ListItem object,adding not only the textual name of the item,but the
value of the item.It produces the following results in the browser:
          <option value="MG2SI04">Olivine</option>

No comments:

Post a Comment