![]() |
|
|
|||||||
![]() |
ASP Net - How to add a value using comboBoxName.Items.Insert |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
(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 |
|
|
|
|
#2 |
|
Posts: n/a
|
few things.
1) look at the asp 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] |
|
|
|
#3 |
|
Posts: n/a
|
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 asp > 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 |
|
|
|
#4 |
|
Junior Member
Join Date: Aug 2008
Posts: 1
|
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 |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|