Solved

Skmmenu adding menus through xml and dynamically doesnt work

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

Industry Leaders: 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

737 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