将xml数据源绑定到下拉列表

编程入门 行业动态 更新时间:2024-10-28 05:22:48
本文介绍了将xml数据源绑定到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

HI all, i有这个xml文件

HI all, i have this xml document

<RolesList> <Roles ID="01"> <Role> <text>HO Admin</text> <value>1</value> </Role> <Role> <text>Circle Admin</text> <value>2</value> </Role> <Role> <text> Branch Admin</text> <value>3</value> </Role> </Roles> <Roles ID="02"> <Role> <text> Branch Admin</text> <value>3</value> </Role> </Roles> </RolesList>

i希望将此xml绑定到我的下拉列表 但是我无法绑定它 我亲自检查一下loged的角色 然后根据它选择一个节点然后我想要将该节点绑定到下拉列表 这里是我的代码:

i want to bind this xml to my dropdown list but i m not able to bind it firt i check for role of loged in person and then select a node basing on that and then i want to bind that node to dropdownlist here is my code:

XmlDataSource oXmlDataSource = new XmlDataSource(); oXmlDataSource.XPath = "siteMap/siteMapNode"; XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("~/Web/sitemap/LoadRole.xml")); XmlNode root = doc.DocumentElement; XmlNodeList nodeList = doc.SelectNodes("/RolesList/Roles[@ID=" + UserRole + "]"); drpUpdateRole.Items.Insert(0, new ListItem(string.Empty, string.Empty)); List<ListItem> items = new List<ListItem>(); foreach (XmlNode node in nodeList) { for (int i = 0; i < node.ChildNodes.Count; i++) { items.Add(new ListItem(node.ChildNodes[i].Attributes["text"].Value, node.ChildNodes[i].Attributes["value"].Value)); } } drpUpdateRole.Items.AddRange(items.ToArray());

但它无法正常工作.. :( 请帮帮我.. 提前谢谢 上帝保佑你们所有..:)

but it is not working..:( please help me.. thank you in advance god bless u all..:)

推荐答案

csharpdotnetfreak.blogspot/2012/06/read-xml-file-into-datatable-aspnet-cvb.html [ ^ ] 创建数据表...而不是使用此数据表绑定下拉列表...:) csharpdotnetfreak.blogspot/2012/06/read-xml-file-into-datatable-aspnet-cvb.html[^] create datatable ... and than bind dropdown using this datatable... :)

嗨 只是我修改了你的代码并根据你的需要制作...... Hi just i modified your code and make it according to your need... { XmlDataSource oXmlDataSource = new XmlDataSource(); oXmlDataSource.XPath = "siteMap/siteMapNode"; XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath(".") + "\\LoadRole.xml"); XmlNode root = doc.DocumentElement; // XmlNodeList nodeList = doc.SelectNodes("/RolesList/Roles[@ID=" + UserRole + "]"); XmlNodeList nodeList = doc.SelectNodes("/RolesList/Roles[@ID=01]"); drpUpdateRole.Items.Insert(0, new ListItem(string.Empty, string.Empty)); List<ListItem> items = new List<ListItem>(); foreach (XmlNode node in nodeList) { for (int i = 0; i < node.ChildNodes.Count; i++) { string text = node.ChildNodes[i].InnerXml; string xml = @"<Test>" + text + "</Test>"; XDocument doc2 = XDocument.Parse(xml); //Get your wood nodes and values in a list List<Tuple<string, string>> list = doc2.Descendants().Select(a => new Tuple<string, string>(a.Name.LocalName, a.Value)).ToList(); items.Add(new ListItem(list[1].Item2, list[2].Item2)); } } drpUpdateRole.Items.AddRange(items.ToArray()); }

jmd : - )

jmd :-)

r4r.co.in/asp/01/tutorial/asp/How%20to%20populate%20combobox%20from%20xml%20file%20using%20c-Sharp%20in %20asp.shtml [ ^ ]

更多推荐

将xml数据源绑定到下拉列表

本文发布于:2023-11-12 23:24:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据源   绑定   列表   xml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!