如何连接两个下拉列表 [英] how to connect two dropdownlists
本文介绍了如何连接两个下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个dropdownlist(classdropdown),其中有一个类列表.我想要另一个具有关联类名称列表的下拉列表(Namedropdown).我希望名称下拉列表在班级下拉列表中选择关联的班级时显示所有名称.这是可以正常运行的class dropdown calss代码.我如何将它们链接在一起.我可以知道C#代码吗??
I have a dropdownlist(classdropdown) which has alist of classes. i want another dropdownlist (Namedropdown) having the list of names of associated class. i want the name dropdownlist to show allthe names when the associated class is selected in the class dropdown. here is the class dropdown calss code which works fine. how do i link them both. may i know the c# code please.?
protected void Page_Load(object sender, EventArgs e)
{
LoadXML();
}
public voidLoadXML()
{
string myXMLfile = Server.MapPath("~/OrgClasses.xml");
DataSet dsClass = new DataSet();
try
{
dsClass.ReadXml(myXMLfile);
ClassDropDownList.DataSource = dsClass;
ClassDropDownList.DataTextField ="ClASS";
ClassDropDownList.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
推荐答案
DropDownList1:
使用OnSelectedIndexChanged事件.
读取DropDownList1的selectedValue并将该值用作输入以检索其他数据并将其绑定到DropDownList2.
就这样
提示:使用if(!Page.IsPostBack){LoadXML(); }在Page_Load
Well DropDownList1:
use the OnSelectedIndexChanged Event.
Read the selectedValue of DropDownList1 and use that value as input to retrieve the other data and bind that to DropDownList2.
That''s all
TIP: Use if (!Page.IsPostBack) { LoadXML() ; } in the Page_Load
这篇关于如何连接两个下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文