Membuat Drop Down List

<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
   <script runat="server" >

      void Selection_Change(Object sender, EventArgs e)

         // Set the background color for days in the Calendar control
         // based on the value selected by the user from the
         // DropDownList control.
         Calendar1.DayStyle.BackColor =


      void Page_Load(Object sender, EventArgs e)

         // Load data for the DropDownList control only once, when the
         // page is first loaded.

            // Specify the data source and field names for the Text
            // and Value properties of the items (ListItem objects)
            // in the DropDownList control.
            ColorList.DataSource = CreateDataSource();
            ColorList.DataTextField = "ColorTextField";
            ColorList.DataValueField = "ColorValueField";

            // Bind the data to the control.

            // Set the default selected item, if desired.
            ColorList.SelectedIndex = 0;



      ICollection CreateDataSource()

         // Create a table to store data for the DropDownList control.
         DataTable dt = new DataTable();

         // Define the columns of the table.
         dt.Columns.Add(new DataColumn("ColorTextField", typeof(String)));
         dt.Columns.Add(new DataColumn("ColorValueField", typeof(String)));

         // Populate the table with sample values.
         dt.Rows.Add(CreateRow("White", "White", dt));
         dt.Rows.Add(CreateRow("Silver", "Silver", dt));
         dt.Rows.Add(CreateRow("Dark Gray", "DarkGray", dt));
         dt.Rows.Add(CreateRow("Khaki", "Khaki", dt));
         dt.Rows.Add(CreateRow("Dark Khaki", "DarkKhaki", dt));

         // Create a DataView from the DataTable to act as the data source
         // for the DropDownList control.
         DataView dv = new DataView(dt);
         return dv;


      DataRow CreateRow(String Text, String Value, DataTable dt)

         // Create a DataRow using the DataTable defined in the
         // CreateDataSource method.
         DataRow dr = dt.NewRow();

         // This DataRow contains the ColorTextField and ColorValueField
         // fields, as defined in the CreateDataSource method. Set the
         // fields with the appropriate value. Remember that column 0
         // is defined as ColorTextField, and column 1 is defined as
         // ColorValueField.
         dr[0] = Text;
         dr[1] = Value;

         return dr;



<head runat="server">
    <title> DropDownList Data Binding Example </title>

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

      <h3> DropDownList Data Binding Example </h3>

      Select a background color for days in the calendar.

      <br /><br />

      <asp:Calendar id="Calendar1"

      <br /><br />

      <table cellpadding="5">



               Background color:





               <asp:DropDownList id="ColorList"







Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: