how to use dropdownlist in asp.net
front end /user inter face
="ProductOrderByCustomer.aspx
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="ProductOrderByCustomer.aspx.cs"
Inherits="ProductOrderByCustomer"
%>
<!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></title>
<style type="text/css">
.style1
{
width:
100%;
}
.style2
{
height:
23px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td align="center" colspan="2">
PRODUCT / SERVICES ENQUIRE</td>
</tr>
<tr>
<td class="style2">
Customer Name :</td>
<td class="style2">
<asp:TextBox ID="TextBox1" runat="server" Width="216px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Email Id :</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" Width="216px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Mobile No :</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Width="139px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Land Line :</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" Width="138px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
State City Area :</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>-Slelect
State-</asp:ListItem>
<asp:ListItem>Bihar</asp:ListItem>
<asp:ListItem>Odisha</asp:ListItem>
<asp:ListItem>West
Bengal</asp:ListItem>
<asp:ListItem>Jharkhand</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>-Select
City-</asp:ListItem>
<asp:ListItem>Patna</asp:ListItem>
<asp:ListItem>Darbhanga</asp:ListItem>
<asp:ListItem>Madhubani</asp:ListItem>
<asp:ListItem>BBSR</asp:ListItem>
<asp:ListItem>Cuttack</asp:ListItem>
<asp:ListItem>Balasore</asp:ListItem>
<asp:ListItem>Bhadrak</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem>-Select
Area-</asp:ListItem>
<asp:ListItem>Link
Road</asp:ListItem>
<asp:ListItem>Badambadi</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Product / Services :</td>
<td>
Catagory :
<asp:DropDownList ID="DropDownList4" runat="server" Height="20px"
onselectedindexchanged="DropDownList4_SelectedIndexChanged"
onclick="DropDownList4_SelectedIndexChanged"
Width="160px" AutoPostBack="True">
</asp:DropDownList>
<asp:Button ID="Button5" runat="server" onclick="Button5_Click" Text="Description" />
<asp:TextBox ID="TextBox8" runat="server" Height="57px" TextMode="MultiLine" Width="227px"
></asp:TextBox>
<asp:Button ID="Button4" runat="server" Text="Select" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" Height="60px" TextMode="MultiLine"
Width="468px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Special Interest :</td>
<td>
<asp:TextBox ID="TextBox6" runat="server" Height="53px" TextMode="MultiLine"
Width="305px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<br />
<asp:Button ID="Button1" runat="server" Height="33px" onclick="Button1_Click"
Text="Submit" Width="92px"
/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
back end /database
ProductOrderByCustomer.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Net;
using System.Net.Mail;
public partial
class ProductOrderByCustomer
: System.Web.UI.Page
{
SqlConnection
con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString);
protected void Page_Load(object
sender, EventArgs e)
{
con.Open();
if
(!IsPostBack)
{
BindContrydropdown();
}
}
protected void BindContrydropdown()
{
SqlCommand
cmd = new SqlCommand("select DISTINCT Catagory from ProductByAdmin",
con);
SqlDataReader
dr = cmd.ExecuteReader();
if
(dr.Read() == true)
{
DropDownList4.DataTextField = "Catagory";
DropDownList4.Items.Add( dr["Catagory"].ToString());
//
ListBox1.DataTextField = "Catagory";
//
ListBox1.Items.Add(dr["Catagory"].ToString());
}
dr.Close();
}
protected void Button1_Click(object
sender, EventArgs e)
{
}
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs
e)
{
}
protected void Button5_Click(object
sender, EventArgs e)
{
if
(TextBox8.Text == "" ||
TextBox8.Text == null)
{
TextBox8.Text =
DropDownList4.SelectedItem.ToString();
}
else
{
TextBox8.Text = TextBox8.Text + "\n" +
DropDownList4.SelectedValue.ToString();
}
}
}
Contact : +91-9040573923, +91-7008182025
http://sradhawebcreations.com/
http://sradhawebcreations.blogspot.in/
https://facebook.com/sradhawebcreations