How to add a value using comboBoxName.Items.Insert

  • Thread starter Thread starter Ruchika Chadha via .NET 247
  • Start date Start date
R

Ruchika Chadha via .NET 247

(Type your message here)

Hi guys,
I am new to ASP .NET. I have used the following code to add values from a database to a combobox:-

Dim index As Integer = 0
For Each dRows In dSet.Tables(tableName).Rows
comboBoxName.Items.Insert(index, dRows.Item(columnName))
index += 1
Next

The above gives me the following HTML output:-
<select name="cbox" id="cbo_cbo" style="width:152px;">
<option value="ABC">ABC</option>
<option value="DEFG">DEFG</option>
</select>

Is there a way to have different values for - "Text" and "Value" in the combobox. For example - how can i produce
<select name="cbox" id="cbo_cbo" style="width:152px;">
<option value="1">ABC</option>
<option value="2">DEFG</option>
</select>

Thanks in advance!!!
cheers
Ruchika (Richi)
 
few things.
1) look at the asp:DropDownList
2) use a dataset and bind to it


--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


Ruchika Chadha via .NET 247 said:
(Type your message here)

Hi guys,
I am new to ASP .NET. I have used the following code to add values from a database to a combobox:-

Dim index As Integer = 0
For Each dRows In dSet.Tables(tableName).Rows
comboBoxName.Items.Insert(index, dRows.Item(columnName))
index += 1
Next

The above gives me the following HTML output:-
<select name="cbox" id="cbo_cbo" style="width:152px;">
<option value="ABC">ABC</option>
<option value="DEFG">DEFG</option>
</select>

Is there a way to have different values for - "Text" and "Value" in the
combobox. For example - how can i produce
 
When you use the DropDownList, create a ListItem and add the ListItem:

ListItem li = new ListItem("myText", "myValue");
MyDDL.Items.Add(li);

or

MyDDL.Items.Add(new ListItem("myText", "myValue"));

The C# code should be easily translatable to VB.NET.

Dale Preston
MCAD, MCSE, MCDBA
Curt_C said:
few things.
1) look at the asp:DropDownList
2) use a dataset and bind to it


--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


Ruchika Chadha via .NET 247 said:
(Type your message here)

Hi guys,
I am new to ASP .NET. I have used the following code to add values from
a
database to a combobox:-
Dim index As Integer = 0
For Each dRows In dSet.Tables(tableName).Rows
comboBoxName.Items.Insert(index, dRows.Item(columnName))
index += 1
Next

The above gives me the following HTML output:-
<select name="cbox" id="cbo_cbo" style="width:152px;">
<option value="ABC">ABC</option>
<option value="DEFG">DEFG</option>
</select>

Is there a way to have different values for - "Text" and "Value" in the
combobox. For example - how can i produce
 
Back
Top