Solved

Skmmenu adding menus through xml and dynamically doesnt work

Posted on 2006-11-30
9
498 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

13 Experts available now in Live!

Get 1:1 Help Now