0

I am using a drop down server control that is databound to a data source, but I would also like to have a default value ("Select a program") that is hard-coded as the first item of the list.

Code-behind

/// <summary>
/// Page Load
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
    ddPrograms.DataSource = Programs.SelectProgramID(1);
    ddPrograms.DataBind();        
}

Front-end

  <asp:DropDownList ID="ddPrograms" runat="server" DataValueField="ProgramID" DataTextField="Name" AutoPostBack="true">
            <asp:ListItem Text="Select a program" Value="0" Selected="True"></asp:ListItem>   
        </asp:DropDownList>
chobo
  • 31,561
  • 38
  • 123
  • 191

1 Answers1

1

Try setting AppendDataBoundItems="true" on the DropDownList.

<asp:DropDownList ID="ddPrograms" runat="server" DataValueField="ProgramID" DataTextField="Name" AutoPostBack="true" AppendDataBoundItems="true">
        <asp:ListItem Text="Select a program" Value="0" Selected="True"></asp:ListItem>   
    </asp:DropDownList>
Spectre87
  • 2,374
  • 1
  • 24
  • 37