我的级联下拉列表中的问题 [英] Issue in my cascading dropdownlist
本文介绍了我的级联下拉列表中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个下拉菜单,
在第一个下拉列表中我直接从db绑定值,
I am having three dropdowns,
in first dropdown i am binding values from db directly,
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" CssClass="DropDown"
Width="190px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDown1ListView();
}
}
private void DropDown1ListView()
{
SqlConnection pCnn = new SqlConnection(Connection.Con);
SqlDataAdapter da = new SqlDataAdapter("exec usp_dropdownlevel", pCnn);
DataSet ds = new DataSet();
pCnn.Open();
da.Fill(ds);
pCnn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Code";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "---Select---");
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string level = DropDownList1.SelectedItem.ToString();
DropDown2(level);
DropDownList3.SelectedIndex = 0;
}
要绑定第二个下拉列表,我必须从dropdown1获取数据
To bind second dropdown i have to get data from dropdown1
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" CssClass="DropDown"
Width="190px" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
private void DropDownList2(string level)
{
SqlConnection pCnn = new SqlConnection(Connection.Con);
SqlDataAdapter da = new SqlDataAdapter("exec usp_dropdownarea'" + level + "'", pCnn);
DataSet ds = new DataSet();
pCnn.Open();
da.Fill(ds);
pCnn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
DropDownList2.DataSource = ds.Tables[0];
DropDownList2.DataTextField = "Name";
DropDownList2.DataValueField = "Code";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, "---Select Area---");
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string area = DropDownList2.SelectedItem.ToString();
DropDown3(area);
}
要绑定第三个下拉列表,我必须从dropdown2获取数据
To bind third dropdown i have to get data from dropdown2
<asp:DropDownList ID="DropDown3" runat="server" CssClass="DropDown" Width="190px">
</asp:DropDownList>
private void DropDown3(string area)
{
SqlConnection pCnn = new SqlConnection(Connection.Con);
SqlDataAdapter da = new SqlDataAdapter("exec usp_DropDown3'" + area + "'", pCnn);
DataSet ds = new DataSet();
pCnn.Open();
da.Fill(ds);
pCnn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
DropDown3.DataSource = ds.Tables[0];
DropDown3.DataTextField = "Name";
DropDown3.DataValueField = "Code";
DropDown3.DataBind();
DropDown3.Items.Insert(0, "---Select Subject---");
}
}
The issue in this code is dropdown 1 is binding correctly but selecting values in dropdown2 is not changing, first value of the dropdown2 is getting select automatically even if i select some other values from dropdown2
推荐答案
您可以尝试删除更新面板并将页面事件EnableEventValidation设置为False
What you can try is to remove the update panel and set the page event EnableEventValidation to False
这篇关于我的级联下拉列表中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文