读取xml并将数据绑定到ddl中 [英] read xml and bind the data into ddl
本文介绍了读取xml并将数据绑定到ddl中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个xml文件
I have a xml file
<Student>
<Students Name="StudentName" Type="string" symbol="=,%,!=" />
<Students Name="EmployeeName" Type="string" symbol="=,%,!=" />
<Students Name="ManagerName" Type="undefines" symbol="=,%,!=" />
<undefined value="1" Name="Manager1">
<undefined value="2" Name="Manager2">
<Students Name="Level1" Type="string" Operators="=,%,!=" />
<Students Name="Level2" Type="undefines" Operators="=,%,!=" />
我想读这个xml文件并将其绑定到一个下拉列表中,该下拉列表在一个下拉列表中包含名称。
选择drpdownName时,它会显示与之关联的符号。表示学生姓名的手段=%!=以下拉形式。
任何人都可以帮助我
我怎么读它在下拉列表中显示
I want to read this xml file and bind this to a dropdown which contains name in one dropdown .
On selection of drpdownName it shows the symbol associated with it . means for student name it shows = % != in the form of drop down .
Can anyone help me
How i read it and show it in dropdown
推荐答案
在您的aspx页面上添加两个下拉列表。
在页面加载下调用以下函数:
Add two dropdown lists to your aspx page.
Call below function on page load:
public void LoadXML()
{
string myXMLfile = Server.MapPath("~/YourFile.xml");
DataSet ds = new DataSet();
try
{
dsStudent.ReadXml(myXMLfile);
DropDownList1.DataSource = ds;
DropDownList1.DataValueField = "Name";
DropDownList1.DataTextField = "Name";
DropDownList1.DataBind();
DropDownList2.DataSource = ds;
DropDownList2.DataValueField = "Name";
DropDownList2.DataTextField = "symbol";
DropDownList2.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
将SlectedIndex更改事件添加到DropDownList1:
Add SlectedIndex change event to DropDownList1:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
}
如果他们帮助您找到解决方案,请不要忘记将有用的回复标记为答案。
Don''t forget to mark useful responses as Answer if they helped you towards a solution.
这篇关于读取xml并将数据绑定到ddl中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文