DropDownList control that contains items in VB.NET

By using this code you can create a DropDownList control that contains items.
  • 2195

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!

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.