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
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DropDownList Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%-- First Method --%>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
<asp:ListItem>Four</asp:ListItem>
<asp:ListItem>Five</asp:ListItem>
</asp:DropDownList>
<%-- 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>
</asp:DropDownList>
<%-- Third Method --%>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
</html>
.cs
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;
DropDownList3.DataBind();
}
}
ASP Standard Controls
- ASP Label Control
- ASP TextBox Control
- ASP Button Control
- ASP Link Button Control
- ASP ImageButton Control
- ASP HyperLink Control
- ASP DropDownList Control
- ASP ListBox Control
- ASP CheckBox Control
- ASP CheckBoxList Control
- ASP RadioButton Control
- ASP RadioButtonList Control
- ASP Image Control
- ASP ImageMap Control
- ASP Calendar Control
- ASP Table Control
- ASP BulletedList Control
- ASP Hidden Control
- ASP Literal Control
- ASP AdRotator Control
- ASP Panel Control
- ASP PlaceHolder Control
- ASP FileUpload Control
- ASP UserControl
- ASP Custom Control
Random Tips and Tricks
Friday, September 3, 2010
Subscribe to:
Post Comments (Atom)
1 comments:
Sir i am your fan....you are the best.......
Post a Comment