Results 1 to 8 of 8

Thread: [CASE CLOSED]Dropdownlist help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    Red face [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!

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    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");

  3. #3
    Junior Member
    Join Date
    Mar 2006
    Posts
    25

    Re: Dropdownlist help

    And if you want to add both Text and Value:

    ddList.Items.Add(new ListItem("Item1", "value1"));
    Help Me Help You.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    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:
    1. cmd.commandtext = [select statement]
    2. str = cmd.executescalar ()
    3.  
    4. dropdownlist.selectedvalue.toString = str
    Appreciated all helps given. Thanks Guys!

  5. #5
    Junior Member
    Join Date
    Mar 2006
    Posts
    25

    Re: Dropdownlist help

    you might have to loop through all items in the dropdownlist.
    Help Me Help You.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    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!

  7. #7
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: Dropdownlist help

    Quote 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:
    1. cmd.commandtext = [select statement]
    2. str = cmd.executescalar ()
    3.  
    4. 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:
    1. 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.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    204

    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
  •  



Click Here to Expand Forum to Full Width