Prepend and Append Dropdownlist

I'm trying to prepend and append values to DropdownList.  Currently all dropdownlist contain ListItem with Text equal to '- Select -"  and all other database items appended dynamically to control.  Customer now wants to append 'Other' to every list.  I do not want to place in table because I want 'Other' to always be the last item in the list.  How do I do this?

See example control in code section.
<asp:DropDownList ID="Allergies1DDL" runat="server" AppendDataBoundItems="True" 
                                                   DataSourceID="AllergiesDS" DataTextField="Allergy" 
                                                   DataValueField="Allergy" TabIndex="1" Width="12.5em">
                                                   <asp:ListItem Text="-Select-" Value="0"></asp:ListItem></asp:DropDownList>

Open in new window

Robert TreadwellManaging DirectorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, use your DropDownList DataBound event:

Your aspx page code:
<asp:DropDownList ID="Allergies1DDL" runat="server" AppendDataBoundItems="True" DataSourceID="AllergiesDS"
    DataTextField="Allergy" DataValueField="Allergy" TabIndex="1" Width="12.5em" OnDataBound="Allergies1DDL_DataBound">
    <asp:ListItem Text="-Select-" Value="0"></asp:ListItem>
</asp:DropDownList>

Open in new window


Your code behind file:
protected void Allergies1DDL_DataBound(object sender, EventArgs e)
{
    Allergies1DDL.Items.Add(new ListItem("Other", "-1"));
}

Open in new window


You must change the -1 value to a proper value for you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.