XML读取,为dropdownlist绑定值
来源:互联网 发布:为什么要云计算 编辑:程序博客网 时间:2024/06/01 08:47
xml内容:
<?xml version="1.0" encoding="utf-8" ?>
<root>
<column value="1">单项选择题</column>
<column value="2">多项选择题</column>
<column value="3">判断题</column>
<column value="4">论述题</column>
<column value="5">案例分析</column>
<column value="6">面试题</column>
</root>
页面存放一个dropdownlist
<asp:DropDownList ID="ddlsttype" runat="server"> </asp:DropDownList>
。cs代码:
方法:
/// <summary>
/// 绑定试题类型
/// </summary>
private void bindExamType()
{
StringBuilder linklist = new StringBuilder();
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("../data/examtype.xml"));
XmlElement root = xmldoc.DocumentElement;
#region xml绑定dropdownlist(步骤一)
DataTable MyDt;
//创建表头Columns
string str = "";
MyDt = new DataTable();
MyDt.Columns.Add(new DataColumn("code", str.GetType()));//编号
MyDt.Columns.Add(new DataColumn("name", str.GetType()));//名称
#endregion
foreach (XmlNode node in root.ChildNodes)
{
#region xml绑定dropdownlist(步骤二)
DataRow MyDr = MyDt.NewRow();
MyDr[0] = node.Attributes["value"].Value;
MyDr[1] = node.InnerText;
MyDt.Rows.Add(MyDr);
#endregion
linklist.Append(string.Format("<a href='QuestionList.aspx?type={0}'>{1}</a> ", node.Attributes["value"].Value, node.InnerText));
}
this.examtypelist = linklist.ToString();
#region xml绑定dropdownlist(步骤三)
ddlsttype.DataTextField = "name";
ddlsttype.DataValueField = "code";
ddlsttype.DataSource = MyDt;
ddlsttype.DataBind();
ddlsttype.Items.Insert(0, new ListItem("请选择", "-1"));
#endregion
}
- XML读取,为dropdownlist绑定值
- XML文件读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 如何从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- asp.net 读取Xml文件并进行DropDownList数据绑定
- DropDownList 绑定xml 数据
- 绑定的Dropdownlist怎么去实现编辑页面下Dropdownlist读取数据源值的问题
- 本文介绍了如何从XML文件中读取数据绑定到DropDownList。
- 得不到dropdownlist选定的值 值为绑定的
- dropdownlist值的绑定
- dropDownList 控件动态绑定数据和读取
- 用DropDownList绑定Xml数据 [已测试]
- asp:DropDownList绑定xml文件列表
- DataSet绑定Hashtable为DropDownList提供数据源
- SAP常见问题与解决办法 1
- JQuery总结
- Qt多语言支持
- an exception occur reason
- ABAP to copy aggregates from one cube to another
- XML读取,为dropdownlist绑定值
- 制作ssis注意事项
- Android入门第十五篇之ActivityGroup + GridView 实现Tab分页标签
- 大战jnlp文件的浏览器自动打开!
- 悲剧啊
- 输出1~100内前五个可以被3整除的数
- Using System.getProperty(String key) to retrieve system properties
- “AspNetPager1_PageChanging”的重载均与委托“System.EventHandler”不匹配
- vc2003 unable to start debugging 有效解决!