Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - How to add a value using comboBoxName.Items.Insert

 
Thread Tools Search this Thread
Old 08-05-2004, 12:42 AM   #1
Default 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>


Ruchika Chadha via .NET 247
  Reply With Quote
Old 08-05-2004, 02:39 AM   #2
Curt_C [MVP]
 
Posts: n/a
Default Re: How to add a value using comboBoxName.Items.Insert
few things.
1) look at the aspropDownList
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" <> wrote in message
news:...
> (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>





Curt_C [MVP]
  Reply With Quote
Old 08-06-2004, 03:41 AM   #3
Dale
 
Posts: n/a
Default Re: How to add a value using comboBoxName.Items.Insert
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:...
> few things.
> 1) look at the aspropDownList
> 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" <> wrote in message
> news:...
> > (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>

>
>





Dale
  Reply With Quote
Old 08-20-2008, 03:09 PM   #4
teknik
Junior Member
 
Join Date: Aug 2008
Posts: 1
Talking One more thing to remember
In .NET 2003, please also note that you need to turn on AppendDataBoundItems in the properties or this will not work. This drove me nuts for two days. Good Luck.


teknik
teknik is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46