|
-
Apr 27th, 2006, 01:31 AM
#1
Thread Starter
Addicted Member
[CASE CLOSED]Dropdownlist help
Hi,
I've got a dropdownlist that is data binded to a table thus all the values are from the table. But how can I display the dropdown list with my own values and the table's values?
Regards,
Roger
Last edited by Aka Roger; Apr 27th, 2006 at 07:54 PM.
Appreciated all helps given. Thanks Guys! 
-
Apr 27th, 2006, 03:24 AM
#2
Re: Dropdownlist help
Yes you can add items to a dropdownlist after it has been bound in a couple of different ways.
ie.
Code:
//Populate Sector Combo
this.ddlSector.DataSource = flaxwebnet.BusinessLogic.Sector.Combo();
this.ddlSector.DataTextField = "Value";
this.ddlSector.DataValueField = "ID";
this.ddlSector.DataBind();
//Add at the end
this.ddlSector.Items.Add("Test_end");
//Insert in a position
this.ddlSector.Items.Insert(0, "Test_insert");
-
Apr 27th, 2006, 03:34 AM
#3
Junior Member
Re: Dropdownlist help
And if you want to add both Text and Value:
ddList.Items.Add(new ListItem("Item1", "value1"));
-
Apr 27th, 2006, 04:20 AM
#4
Thread Starter
Addicted Member
Re: Dropdownlist help
Thanks a lot guys, I got it to work. However, I got one question about drop down list.
For example, in the dropdown list, when the user chooses "Item1", it will be added to the database. When I want to display the drop down list, the selected item will be "Item1". But it could not work.
Coding:
VB Code:
cmd.commandtext = [select statement]
str = cmd.executescalar ()
dropdownlist.selectedvalue.toString = str
Appreciated all helps given. Thanks Guys! 
-
Apr 27th, 2006, 04:52 AM
#5
Junior Member
Re: Dropdownlist help
you might have to loop through all items in the dropdownlist.
-
Apr 27th, 2006, 04:57 AM
#6
Thread Starter
Addicted Member
Re: Dropdownlist help
But is my coding correct? I'm very sure that my SQL statement is correct but I am not sure about the selectedValue.toString()
Appreciated all helps given. Thanks Guys! 
-
Apr 27th, 2006, 08:02 AM
#7
Frenzied Member
Re: Dropdownlist help
 Originally Posted by Aka Roger
Thanks a lot guys, I got it to work. However, I got one question about drop down list.
For example, in the dropdown list, when the user chooses "Item1", it will be added to the database. When I want to display the drop down list, the selected item will be "Item1". But it could not work.
Coding:
VB Code:
cmd.commandtext = [select statement]
str = cmd.executescalar ()
dropdownlist.selectedvalue.toString = str
If you are trying to set which item in the dropdownlist is selected, there are functions in there to do that. Look at DropDownList.Items.FindByValue. Kind of like:
VB Code:
MyDDL.SelectedIndex = MyDDL.Items.IndexOf(MyDDL.Items.FindByValue(MyString))
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Apr 27th, 2006, 07:53 PM
#8
Thread Starter
Addicted Member
Re: Dropdownlist help
Thanks a lot. I got it to work without looping it.
Appreciated all helps given. Thanks Guys! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|