Friday, September 3, 2010

DropDownList Server Control

The DropDownList server control enables you to place an HTML select box on your Web page and program against it. It's deal when you have a large collection of items from which you want the user to select a single item.

Dynamically Generating a DropDownList


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
<title>DropDownList Example</title>
<form id="form1" runat="server">
<%-- First Method --%>
<asp:DropDownList ID="DropDownList1" runat="server">

<%-- Second Method --%>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Text="" Value="0" Selected="True"></asp:ListItem>
<asp:ListItem Text="Red" Value="Red"></asp:ListItem>
<asp:ListItem Text="Yellow" Value="Yellow"></asp:ListItem>
<asp:ListItem Text="Orange" Value="Orange"></asp:ListItem>
<asp:ListItem Text="Blue" Value="Blue"></asp:ListItem>
<asp:ListItem Text="NoColor" Value="NoColor"></asp:ListItem>

<%-- Third Method --%>

<asp:DropDownList ID="DropDownList3" runat="server">



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

//Third Method
string[] Cars = { "Honda", "Maruthi", "Suzuki", "Benz", "BMW" };

DropDownList3.DataSource = Cars;


No comments:

Post a Comment