How to do multiple dropdown list??

Jun 17 2017 12:41 PM
i have done one dropdown list.but i need to attach multiple dropdown.
how to do that? i have done in the following code. please tell is it correct or not?and if not please tell me the right way to do that.
reply asap. 
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using MySql.Data.MySqlClient;
using System.Data;
namespace entry
{
public partial class def2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
populatedept();
}
}
public void populatedept()
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("select id,department from department_names", con);
MySqlDataAdapter adpt = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adpt.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.DataTextField = "department";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (!IsPostBack)
{
simpledept();
}
}
public void simpledept()
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ConnectionString);
con.Open();
MySqlCommand cmd = new MySqlCommand("select id,functions from function_list",con);
MySqlDataAdapter adpt = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adpt.Fill(dt);
DropDownList2.DataSource = dt;
DropDownList2.DataBind();
DropDownList2.DataTextField = "functions";
DropDownList2.DataValueField = "id";
DropDownList2.DataBind();
}
}
}
 

Answers (3)