结合嵌套的XML来的CheckBoxList [英] Binding nested XML to CheckboxList

查看:135
本文介绍了结合嵌套的XML来的CheckBoxList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套的 XML 文件,其中包含菜单和子菜单。我需要将其绑定到页面加载asp.net CheckBox控件。

我想用下面

在C#code绑定

C#:

 的DataSet DS =新的DataSet();
尝试
{    //读取从XML文件中的数据
    ds.ReadXml(HttpContext.Current.Server.MapPath(〜/ menu.xml文件));
    数据视图数据视图= ds.Tables [0] .DefaultView;
    BioCheckBoxList.DataSource =数据视图;
    BioCheckBoxList.DataBind();
 }

XML:

 <菜单>
  <菜单项文本=家URL =?〜/ Default.aspx的ID = e058511b-b7d9-4d39-B194-cf803014777中等=08f360dc- a9cf-4724-a595-66f7ca01c04epredeficon =homeico />
  <菜单项文本=生物URL =〜/ Default.aspx的图标=〜/普通/主题/ smoothadmin / IMG / cog.png>
    <子>
      <菜单项文本=注册URL =〜\\模块\\生物\\ Reg.aspx/>
      <菜单项文本=纪念品URL =〜\\模块\\生物\\ Mem.aspx/>
    < /子>
  < /菜单项>  <菜单项文本=PORURL =〜/ Default.aspx的?图标=〜/普通/主题/ smoothadmin / IMG / cog.png>
    <子>
      <菜单项文本=常规&GT​​;
        <子>
          <菜单项文本=预约URL =〜\\模块\\门户\\ Gen.aspx/>
        < /子>
      < /菜单项>
    < /子>
  < /菜单项>
&所述; /菜单>


解决方案

  1. 使用的网站而不是XML文件。在这里看到:使用菜单和-Sitemap与 - 主页


  2. 使用的 TreeView控件控制和TreeView控件绑定到网站地图。


  3. TreeView控件 ShowCheckBoxes 属性设置为全部


I have a nested xml file which contains menu and submenus. I need to bind it to the asp.net CheckBox control on page load.

I am trying to bind using the C# code below

C#:

DataSet ds = new DataSet();
try
{

    //Reading the data from  the XML file
    ds.ReadXml(HttpContext.Current.Server.MapPath("~/menu.xml"));
    DataView dataview = ds.Tables[0].DefaultView; 
    BioCheckBoxList.DataSource = dataview ;
    BioCheckBoxList.DataBind();            
 }  

XML:

<menu>
  <menuItem text="Home" url="~/Default.aspx?id=e058511b-b7d9-4d39-b194-cf803014777" mid="08f360dc-   a9cf-4724-a595-66f7ca01c04e" predeficon="homeico" />
  <menuItem text="Bio" url="~/Default.aspx"  icon="~/common/theme/smoothadmin/img/cog.png">
    <subMenu>
      <menuItem text="Reg" url="~\Modules\Bio\Reg.aspx"/>
      <menuItem text="Mem" url="~\Modules\Bio\Mem.aspx"/>      
    </subMenu>
  </menuItem>

  <menuItem text="Por" url="~/Default.aspx?"  icon="~/common/theme/smoothadmin/img/cog.png">
    <subMenu>
      <menuItem text="General">
        <subMenu>
          <menuItem text="Make Appointment" url="~\Modules\Portals\Gen.aspx"/>          
        </subMenu>
      </menuItem>
    </subMenu>
  </menuItem>
</menu>

解决方案

  1. Use SiteMap instead of XML file. See here: Using-Menu-and-Sitemap-with-Master-page

  2. Use an TreeView control and bind TreeView to SiteMap.

  3. In TreeView the ShowCheckBoxes property set to All.

这篇关于结合嵌套的XML来的CheckBoxList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆