You must Sign In to post a response.
  • Category: ASP.NET

    Add a new field to a dynamic dropdownlist

    I have a country dropdownlist which is dynamic.I have to add a new field Other as the last field in the dropdown.How to do that?
  • #754136

    You can add it from code level and sql level.
    Suppose your sql query is
    select countryID,countryCode from Country

    then you should write
    select 'others' as countryID,'others' countryCode 
    union all
    select countryID,countryCode from Country

    Otherwise you can add list item to dropdown and set appenddatabounds property "true" and you will get your solution.

    I hope you got my point, if still you have an isse than i'll et back to you.

    Nirav Prabtani (Senior Web Developer)
    Email :
    blog :

  • #754144
    can you please explain "Otherwise you can add list item to dropdown and set appenddatabounds property "true" and you will get your solution." with an example

  • #754177

    Lets use like this:

    DDL_DropDown.Items.Insert(0, new ListItem("Email Address", "Email"));

    Here "0" is the index value can give index value that which position do you want to show...if you want to show as last list value means just count db values and give count value to index value..i hope it will work...

  • #754207

    If you have the drop down list Id then you can easily add any item to it. for example.

    ddlName.Items.Insert(ddlName.Items.Count, "-Select-");

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #754212

    hope below code will help u out..

    ddlFruits.Items.Add(new ListItem(fruit, fruit));


  • #760828

    You can additem in Dropdownlist means

    try this code

    <asp:DropDownList ID="Drp1" runat ="server">
    <asp:ListItem Text="Asp" Value="1"></asp:ListItem>
    <asp:ListItem Text="C#" Value="2"></asp:ListItem>
    Drp1.Items.Insert(0, "--Select Item");
    ddlFruits.Items.Add(new ListItem(0, "Select Item"));

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • Sign In to post your comments