Binding nested XML to CheckboxList

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="~ModulesBioReg.aspx"/>
      <menuItem text="Mem" url="~ModulesBioMem.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="~ModulesPortalsGen.aspx"/>          
        </subMenu>
      </menuItem>
    </subMenu>
  </menuItem>
</menu>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

  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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x