?
Solved

Skmmenu adding menus through xml and dynamically doesnt work

Posted on 2006-11-30
9
Medium Priority
?
525 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

771 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