473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to add a value using comboBoxName.Items.Insert

(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)

--------------------------------
From: Ruchika Chadha

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>3pgFRGdVAESIWYDWIgQZMA==</Id>
Nov 18 '05 #1
2 2053
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" <an*******@dotnet247.com> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
(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)

--------------------------------
From: Ruchika Chadha

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>3pgFRGdVAESIWYDWIgQZMA==</Id>

Nov 18 '05 #2
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 [MVP]" <software_AT_darkfalz.com> wrote in message
news:eB*************@TK2MSFTNGP09.phx.gbl...
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" <an*******@dotnet247.com> wrote in message
news:eA**************@TK2MSFTNGP10.phx.gbl...
(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)

--------------------------------
From: Ruchika Chadha

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>3pgFRGdVAESIWYDWIgQZMA==</Id>


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Marty | last post by:
Hi, Ok I use the OLEDBConnector and dataset to retrieve data from my Access DB. I have a problem to read/parse the dataset and I would like to know if I am using the right object to reach my...
3
by: Earl Teigrob | last post by:
I want to write a function where I pass in a reference to a dropdownlist and a "match value" and have it returns the index of the dropdownlist item that matchs (or -1 if there is no match) ...
5
by: DC Gringo | last post by:
I have a dropdownlist that, upon form submission, I'd like to maintain the selected value when I get my result...how do I do that? <asp:dropdownlist Font-Size="8" id="ddlCommunities"...
4
by: Patrick Olurotimi Ige | last post by:
I have a DropDown Lsit set to ddlGetDebtor.Items.Insert(0, "-Select Debtor Code-") which is setting the "-Select Debtor Code-" to be default And on PostBack i'm passng:- Cmd.Parameters.Add(New...
7
by: grummanf6f | last post by:
Hello Gurus, this probably is real simple for you but for me it's a bummer. I have one table in which I have basic data collected of schools. I have another data that is detailed info on the...
7
by: Jim in Arizona | last post by:
Using this: <asp:ListItem Value="0"</asp:ListItem> as long as I have a value listed and leave the area between the tags blank, when viewed the DropDownList will show a 0 as a choice. I want it...
4
by: Pman12 | last post by:
Below is the vba code I am working with. When it gets to the insert part I get an "Enter parameter value" dialog box with the value of the variable "id" above the cursor. I have to type in that...
1
Eleven
by: Eleven | last post by:
Hi everybody! I've got a User Control "SelectBatchByTerminal", that has two dropdown lists, "TerminalDropDownList" and "BatchDropDownList". using System; using System.Data; using...
2
by: franc sutherland | last post by:
Hello, I am using Access 2003. I have a query which shows a list of club meetings sorted by date. This query is displayed in continuous forms, in a subform. I would like to select a month on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.