Initial Value of a DropdownList

Last post 06-18-2007 5:33 AM by LockH. 2 replies.

Sort Posts:

  • Initial Value of a DropdownList

    06-18-2007, 4:39 AM
    • Member
      39 point Member
    • stevenkaitan
    • Member since 05-31-2007, 5:35 AM
    • Posts 56

    Hi,

    I am using a dropdownlist, textbox and a gridview.

    i have populated the dropdownlist with the country codes from a table. based on the selection of the country code i am populating the grid with appropriate values. the drop down list contains codes like 'US','SA','UK','IND','AUS' fetched from the query "SELECT PrmCde,PrmVal from PrmDef"

    PrmCde is the Country Code and PrmVal is the description of the Country like United states, South Africa, United Kingdom, India etc...

    What I am looking for is to set the initial value of the dropdown list to IND and the textbox should display India. On change of the dropdown list value the text box value should change accordingly. I am using Sqldatasource. Any help or alternative to this issuw will be highly appreciated.

    Thanks

    Steve

     

     

     

  • Re: Initial Value of a DropdownList

    06-18-2007, 5:29 AM
    • Member
      343 point Member
    • ziyad
    • Member since 01-17-2004, 8:39 AM
    • Posts 84

    Try this:-

    DropDownList1.Items.FindByValue("IND").Selected = true;

    Marks as answer, if so

  • Re: Initial Value of a DropdownList

    06-18-2007, 5:33 AM
    Answer
    • Contributor
      2,793 point Contributor
    • LockH
    • Member since 03-25-2007, 10:58 AM
    • Scotland, where whisky has no e.
    • Posts 576

    Two solutions:

    1st method

    Add a prmSequence column to the table with country codes, set sequence to 1 on India record, 2 (or anything higher) on other records.

    "Select prmCode, prmVal from prmDef order by prmSequence, prmCde"

     

    2nd method

    In the asp tags, add a first line for India and specify AppendDataItems so that values from the database will be added to the existing value, instead of overwriting it.

    Note that if India is also in the list read from the database, it will appear twice in the DDL, unless you change the sql to include " ... where prmCde <> 'IND' "

    <asp:DropDownList ID="ddlCountry" DataSourceId="sdsCountry" DataTextField="prmCde" DataValueField="prmVal" >

    <asp:ListItem Value="IND" Text="India" />

    runat="server" AppendDataBoundItems="True"

    </asp:DropDownList>

     

    If a post helps to solve your problem, please click the Answer button on that post.

    I'm still confused, but now I'm confused on a higher plane.
Page 1 of 1 (3 items)