ARTICLE

How to create a DropDownList control that contains items

Posted by Manish Dwivedi Articles | ASP.NET using VB.NET April 12, 2007
By using this code you can create a DropDownList control that contains items.
 
Reader Level:

The following code explains you how to create a DropDownList control that contains five items.

Code for Default.aspx:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

 

<script runat="server">

 

    Sub SelectedItem_Change(ByVal sender As Object, ByVal e As EventArgs)

 

' Here we set the background color for days in the calender control based on the selected value in the DropDownList control.

        Calendar1.DayStyle.BackColor = _

            System.Drawing.Color.FromName(ColorList.SelectedItem.Value)

 

    End Sub

 

</script>

 

<body>

    <form id="Form1" runat="server">

        <h3>

            DropDownList Example

        </h3>

        Select a background color for days in the calendar.

        <br>

        <br>

        <asp:Calendar ID="Calendar1" ShowGridLines="True" ShowTitle="True" runat="server" />

        <br>

        <br>

        <table cellpadding="5">

            <tr>

                <td>

                    Background color:

                </td>

            </tr>

            <tr>

                <td>

                    <asp:DropDownList ID="DropDownListColors" AutoPostBack="True" 

                      OnSelectedIndexChanged="SelectedItem_Change" runat="server">

                        <asp:ListItem Selected="True" Value="Black"> Black /asp:ListItem>

                        <asp:ListItem Value="Green"> Green </asp:ListItem>

                        <asp:ListItem Value="Blue"> Blue </asp:ListItem>

                        <asp:ListItem Value="Silver> Silver</asp:ListItem>

                        <asp:ListItem Value="Yellow"> Yellow </asp:ListItem>

                    </asp:DropDownList>

                </td>

            </tr>

    </form>

</body>

</html>

Happy Coding!

share this article :
post comment
 

in dropdownlist can't select the purticular item in if condition. i use if(dropdownlist1.selecteditem.tostring()="green")

Posted by uma Jan 31, 2008
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor