.NET Diary

October 28, 2009

DropDown List With HardCoded Values with Default Selected a value

Filed under: ASP.NET, All, C# — leoullas @ 10:41 am

There are two ways:

 

Way 1:

In aspx file:

     <td style=”width: 90px; height: 56px;” valign=”middle”>

        <asp:DropDownList ID=”ddlTime” runat=”server” Width=”131px” onchange=”clickClient();”  Height=”19px”>

</asp:DropDownList>

     </td>

In aspx.CS file:

    public static void PopulateDdlTime(DropDownList ddlTime)

    {

        ddlTime.Items.Add(new ListItem(“12:00AM–08:00AM”, “1200AM0800AM”));

        ddlTime.Items.Add(new ListItem(“08:00AM–04:00PM”, “0800AM0400PM”));

        ddlTime.Items.Add(new ListItem(DRISInternatiolization.DRISInternatiolization.GetLabelText(“464″), “Customize”));

        ddlTime.SelectedValue = “0800AM0400PM”;

    }

protected void Page_Load(object sender, EventArgs e)

       {

PopulateDdlTime(ddlTime);

……

……

}

Way 2:

In aspx file:

<td style=”width: 90px; height: 56px;” valign=”middle”>

    <asp:DropDownList ID=”ddlTime” runat=”server” Width=”131px” onchange=”clickClient();” Height=”19px”>

                  <asp:ListItem Value=”1200AM0800AM”>12:00AM–08:00AM</asp:ListItem>

                  <asp:ListItem Value=”0800AM0400PM” Selected=”True”>08:00AM–04:00PM</asp:ListItem>

                  <asp:ListItem Value=”Customize”>Customize…</asp:ListItem>

    </asp:DropDownList>

</td>

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.