Solved

Skmmenu adding menus through xml and dynamically doesnt work

Posted on 2006-11-30
9
504 Views
Last Modified: 2012-06-27
I tried to use the skmmenu control with an xml file to create a menu then I tried to programatically /  dynamically add more menu items. But on databind, i dont see these new items. It seems like skmmenu will work with just xml or just dynamic menus not both

Is this true ?
0
Comment
Question by:opstechnology
  • 3
  • 2
9 Comments
 
LVL 5

Expert Comment

by:Collindsouza
ID: 18050666
Don't you mean that you want to inset xml nodes dynamically into the Menu.xml file ??
0
 

Author Comment

by:opstechnology
ID: 18050684
no i mean i create a menu using an xml file like this
This is the XML file simplexml.xml
******************************************************************
<?xml version="1.0" encoding="utf-8" ?>
<menu>
      <menuItem>
            <text>Admin</text>
            <width>100</width>
            <subMenu>
                  <menuItem>
                        <url>fraBudgetEntrySearch.aspx</url>
                        <text>Budget Entry Search</text>
                        <target>fbody</target>
                  </menuItem>
            </subMenu>
      </menuItem>
      <menuItem id="2.0">
            <text>Reports</text>
      </menuItem>
</menu>

************************************************************************
This is my code

Protected WithEvents Menu1 As skmMenu.Menu

Menu1.DataSource = Server.MapPath("SimpleXML.xml")
Menu1.Layout = skmMenu.MenuLayout.Horizontal
Menu1.DataBind()

'Then I'd like to add more menus dynamically

                Dim men As New skmMenu.MenuItem
                Dim submen As New skmMenu.MenuItem

                submen.Text = "Nothing"

                men.Url = "http://www.yahoo.com"
                men.Text = "Yahoo!"
                men.Target = "fbody"

                Dim ind As Integer

                submen.SubItems.Add(men)
                Menu1.Items.Add(submen)

I dont see this new menu item when i run the app

But if i just dynamically add (no xml) then i see it. How can i use both ?
0
 
LVL 5

Accepted Solution

by:
Collindsouza earned 500 total points
ID: 18050782
example:

SqlDataReader GroupMenuDataReader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text, "SELECT * FROM MENUS");
while (GroupMenuDataReader.Read())
{
GroupMenu MyGroupMenu = new GroupMenu();
MyGroupMenu.MenuId = int.Parse(GroupMenuDataReader["MENU_ID"].ToString());
MyGroupMenu.MenuName = GroupMenuDataReader["MENU_NAME"].ToString();
MyGroupMenu.MenuDefaultCssClass = GroupMenuDataReader["MENU_DEFAULTCSSCLASS"].ToString();
etc...

Flag = false;
TextWriter stringWriter = new StringWriter();
XmlTextWriter MyXmlTextWriter = new XmlTextWriter(stringWriter);
DataSet MyDataSet = OracleHelper.ExecuteDataset(ConnectionString, CommandType.Text, "SELECT * FROM MENU_ITEMS WHERE (MENU_ID = " + MyGroupMenu.MenuId + ")");

MyXmlTextWriter.WriteStartDocument();
MyXmlTextWriter.WriteStartElement("menu");

GatherMenuItems(ref MyXmlTextWriter, ref MyDataSet,0);

XmlDocument MyXmlDocument = new XmlDocument();
MyXmlDocument.LoadXml(stringWriter.ToString());
XmlFileSrc = "MenuData" + MyGroupMenu.MenuId + GroupId + ".xml";
MyXmlDocument.Save(XmlFileSrc);
MyGroupMenu.DataSource = XmlFileSrc;
MyDataSet.Clear();
}
GroupMenuDataReader.Close();



----------
private void GatherMenuItems(ref XmlTextWriter MyXmlTextWriter, ref DataSet MyDataSet, int ParentMenuItemId)
{
DataRow[] FilterDataRow;
FilterDataRow = MyDataSet.Tables[0].Select("PARENT_MENUITEM_ID = '" + ParentMenuItemId + "'","MENUITEM_ORDER");

if (Flag == true && FilterDataRow.Length > 0)
{
MyXmlTextWriter.WriteStartElement("subMenu");
}

for (int x=0; x<FilterDataRow.Length; x++)
{

if (FilterDataRow[x]["MENUITEM_TYPE"] != System.DBNull.Value)
{
if (FilterDataRow[x]["MENUITEM_TYPE"].ToString() == "MenuSeparator")
{
MyXmlTextWriter.WriteStartElement("menuSpacer");
MyXmlTextWriter.WriteStartElement("spacermarkup");
MyXmlTextWriter.WriteStartElement("hr");
MyXmlTextWriter.WriteEndElement();
MyXmlTextWriter.WriteEndElement();
MyXmlTextWriter.WriteEndElement();
continue;
}
}

Flag = true;
MyXmlTextWriter.WriteStartElement("menuItem");


if (FilterDataRow[x]["MENUITEM_TEXT"] != System.DBNull.Value)
{
MyXmlTextWriter.WriteStartElement("text");
MyXmlTextWriter.WriteString(FilterDataRow[x]["MENUITEM_TEXT"].ToString());
MyXmlTextWriter.WriteEndElement();
}

etc...
GatherMenuItems(ref MyXmlTextWriter, ref MyDataSet, int.Parse(FilterDataRow[x]["MENUITEM_ID"].ToString()));
MyXmlTextWriter.WriteEndElement();
}

if (Flag == true && FilterDataRow.Length > 0)
{
MyXmlTextWriter.WriteEndElement();
}
}
0
 

Author Comment

by:opstechnology
ID: 18055385
Can u give me an example where part of the menu is pulled from an xml file and the rest of the menu items are adding programatically?
0
 
LVL 5

Expert Comment

by:Collindsouza
ID: 18290890
why delete?? experts have provided a valid solution...
i suggest please split points between opstechnology and Collindsouza
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now