[英]how to bind data to the dropdownlist on selected value of the other dropdownlist in asp.net?? I have already bind data to the all the dropdown
//.aspx.cs代碼:
protected void ddldistrict_SelectedIndexChanged(object sender, EventArgs e)
{
try {
ddltaluka.Enabled = true;
string d1 = ddldistrict.Text;
NpgsqlConnection conn = new NpgsqlConnection("Server=localhost;Port=5432;User Id=postgres;Password=*******;Database=guj_data;");
conn.Open();
string sql = "SELECT tname FROM taluka_geo_bnd_box WHERE district='"+d1+"'";
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
ds.Reset();
da.Fill(ds);
dt = ds.Tables[0];
ddltaluka.DataSource = ds;
ddltaluka.DataTextField = "tname";
ddltaluka.DataBind();
conn.Close();
}
catch(Exception e3)
{
throw e3;
}
}
protected void ddltaluka_SelectedIndexChanged(object sender, EventArgs e)
{
try {
ddlvillage.Enabled = true;
string t1 = ddltaluka.Text;
string d1 = ddldistrict.Text;
NpgsqlConnection conn = new NpgsqlConnection("Server=localhost;Port=5432;User Id=postgres;Password=*****;Database=guj_data;");
conn.Open();
string sql = "SELECT vname FROM village_boundary_geo_bnd_box WHERE tname='"+t1+"' AND district='"+d1+"'";
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
ds.Reset();
da.Fill(ds);
dt = ds.Tables[0];
ddlvillage.DataSource = ds;
ddlvillage.DataTextField = "vname";
ddlvillage.DataBind();
conn.Close();
}
catch(Exception e4)
{
throw e4;
}
}
如果我正確理解你的話; 當調用方法ddltaluka_selectedIndexChanged時,ddlvillage數據綁定發生在頁面加載時,您嘗試綁定新數據嗎,但是它又回到了原始的ddlVillage列表?
如果是這種情況,您只需要在初始頁面加載時對ddlVillage進行初始數據綁定,而不必每次回發
if (!IsPostBack)
{
//bind your initial data here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.