Hide siteMapNode when at particular view - asp.net

I have siteMapNode inside SiteMap in Web.sitemap and want to hide one of the menu items, when I am at the page .../example.aspx?title=hiding
I tried to hide that menu from example.aspx.cs at Page_Load with smth like:
MenuItemCollection menuItems = Menu.Items;
MenuItem menuItem = new MenuItem();
foreach (MenuItem item in menuItems)
{
if (item.Text == "home")
menuItem = item;
}
menuItems.Remove(menuItem);
but I couldn't find needed item. Also I have tried to add logic into MenuTop_MenuItemDataBound, but it isn't executing at every url change

Related

JavaFX TreeView hide context menu when tree is empty

I have a TreeView with a context menu, all works except when tree is empty. When tree is empty, I want to prevent show context menu to user.
//Set up context menu and menu items
final ContextMenu contextMenu = new ContextMenu();
final MenuItem miSubir = new MenuItem("Subir");
final MenuItem miBajar = new MenuItem("Bajar");
final MenuItem miBorrar = new MenuItem("Borrar");
//add events from clic on menu items
miBorrar.setOnAction((ActionEvent event) -> {
...
});
...
//Add menu items to context menu
contextMenu.getItems().add(miSubir);
contextMenu.getItems().add(miBajar);
contextMenu.getItems().add(miBorrar);
//Associate context menu to treeview
treeEjercicios.setContextMenu(contextMenu);
When I use Table component, I fix the problem with:
row.contextMenuProperty().bind(
Bindings.when(row.emptyProperty())
.then((ContextMenu) null)
.otherwise(contextMenu)
);
But I don't know how to apply to use with TreeView or any other alternative?
If the root item is shown, i.e. tree.setShowRoot(true), it can be supposed that when the root item is null the treeview is empty. So we can bind it
tree.contextMenuProperty().bind(
Bindings.when( Bindings.isNull( tree.rootProperty() ) )
.then( (ContextMenu) null)
.otherwise( contextMenu )
);
Else if the root item is not show, then the tree can be supposed to be empty if this root item has no children, i.e. when isLeaf() returns true. In this case the binding will be:
tree.contextMenuProperty().bind(
Bindings.when( tree.getRoot().leafProperty() )
.then( ( ContextMenu ) null )
.otherwise( contextMenu )
);

Possible to created a submenu programmatically in c#?

On my page theres buttons on the top. I would like to add sub menus to those buttons:
protected void AddMenuItems()
{
// Check privledges and add links to admin pages accordingly.
// List adds pages in order of user precedence.
if (_cu.IsUser)
{
NavigationMenu.Items.Add(new MenuItem("Generate UserIDs", "Generate UserIDs", null, "~/GenPrefixList.aspx"));
}
}
Is there a way I can add a sub menu to the item?
Yes, each MenuItem has a ChildItems collection to which you can add an indefinite number of items.
protected void AddMenuItems()
{
// Check privledges and add links to admin pages accordingly.
// List adds pages in order of user precedence.
if (_cu.IsUser)
{
var newItem = new MenuItem("Generate UserIDs", "Generate UserIDs", null, "~/GenPrefixList.aspx");
var subItem = new MenuItem("Sub Menu Item", "Submenu Item", null, "page.aspx");
newItem.ChildItems.Add(subItem);
NavigationMenu.ChildItems.Add(newItem);
}
}
The "Sub Menu Item" will be a child of "Geneate UserIDs", which is a child of the navigation menu.
Update: The Items reference in your code should be ChildItems. Items is the collection used for the Windows application menu; you added the ASP.NET tag so I assume this is a web application.

Dynamically Add/Remove Menu Items in ASP.NET?

I have a menu control (Menu1) and I want to add/remove items from the menu based on certain information I have stored about the authenticated user in the database. I'm not sure though how to access specific menu items from the menu control and remove them at runtime?
ASP.NET menus can be accessed via code behind. A menu declared in the markup, having the id 'Menu1' for example, could be accessed like so:
foreach (MenuItem item in Menu1.Items) {
if (item.NavigateUrl.Contains(pageName)) {
item.Selected = true;
item.Text = "customText";
}
// ...
}
In that example, the currently selected menu item is chosen according to the current page the menu is on. Just as well, the Items collection may be used to add or remove single menu items.
Note, on menu items, the ChildItems collection can be used to alter the submenu items collection.
More infos: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.items.aspx
#Edit: made it more coherent with the data in the question
I wish you was more specific but I know that the notification for comments kinda sucks here. so if you could tell me exactly
what is the information you'll Add/Remove items based on ?
how are they're stored in the database (which means are they are stored in one of the membership tables ? in the profile's table ? or a custom table where the user is referenced in ?
what's the technique you imagine in your mind in plain English ?
I'm not sure though how to access
specific menu items from the menu
control and remove them at runtime?
A. Remove items:
Menu1.Items.Remove(Menu1.FindItem("Jobs"))
B. Add Items:
Menu1.Items.Add(new MenuItem("News"))
OR use this to specify the required
properties for the new added item:
MenuItem item = new MenuItem()
item.NavigateUrl =""
item.Text = "Child Test"
Menu1.Items.Add(mnuTestChild)
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["MyConString"].ConnectionString;
string selectCmd = "Select * from Pages where Status='"+1+"'";
SqlDataAdapter dap = new SqlDataAdapter(selectCmd,con);
DataSet ds = new DataSet();
dap.Fill(ds);
if (!Page.IsPostBack)
{
int x = 0;
string parent_id = "";
foreach (DataRow dr in ds.Tables[0].Rows)
{
parent_id = dr[0].ToString();
Menu1.Items.Add(new MenuItem(dr["Title"].ToString(), dr["URL"].ToString(), dr["ID"].ToString()));
}
x++;
}
}

menu control css based on childitems

I need to set the css on some menu items on its hover based on whether they have childitems or not.
"Home" "Manage Customer" "Manage Employee"
"Customer List" "Employee List"
"Customer Detail" "Employee Detail"
The sample menuitems are shown above. I want "Home","Customer List","Customer Detail","Employee List","Employee Detail" to have one css on hover (as they do not have any children)
and "Manage Customer","Manage Employee" should have a different css.
How do I achieve that.
Code
protected void Page_Load(object sender, EventArgs e)
{
MenuItem miHome = new MenuItem("Home", "0");
miHome.NavigateUrl = "http://www.google.com";
MenuItem miManageCustomer = new MenuItem("Manage Customer", "1");
miManageCustomer.NavigateUrl = "javascript:void(0)";
MenuItem miCustomerList = new MenuItem("Customer List", "2");
miCustomerList.NavigateUrl = "http://www.google.com";
miManageCustomer.ChildItems.Add(miCustomerList);
MenuItem miCustomerDetail = new MenuItem("Customer Detail", "3");
miCustomerDetail.NavigateUrl = "http://www.google.com";
miManageCustomer.ChildItems.Add(miCustomerDetail);
MenuItem miManageEmployee = new MenuItem("Manage Employee", "4");
miManageEmployee.NavigateUrl = "javascript:void(0)";
MenuItem miEmployeeList = new MenuItem("Employee List", "5");
miEmployeeList.NavigateUrl = "http://www.google.com";
miManageEmployee.ChildItems.Add(miEmployeeList);
MenuItem miEmployeeDetail = new MenuItem("Employee Detail", "6");
miEmployeeDetail.NavigateUrl = "http://www.google.com";
miManageEmployee.ChildItems.Add(miEmployeeDetail);
menu1.Items.Add(miHome);
menu1.Items.Add(miManageCustomer);
menu1.Items.Add(miManageEmployee);
}
Assuming a HTML structure like this:
<ul id="menu">
<li>Home</li>
<li>Manage Customer
<ul>
<li>Customer List</li>
<li>Customer Detail</li>
</ul>
</li>
</ul>
You can actually use the .not function together with the :only-child selector, like this:
$('#menu > li > a').not(':only-child')
See: http://jsfiddle.net/KWHf6/. However, if you're only doing this to style them, then I'd suggest you add a class to each of the li that have the submenus, so as to remove the Javascript dependency.
You could add a cssClass property to the MenuItem class (if one doesn't already exist), and set it when populating the menu. Then you'd have to use that cssClass property when rendering menu items to html.
Now, i don't know what does the MenuItem class look like so this is a pretty generic solution.

How do you hidden/show particular context menu item in flex?

var contextMenu:ContextMenu = new ContextMenu();
contextMenu.hideBuiltInItems();
var contactList : ContextMenuItem = new ContextMenuItem("Add to Existing List");
contactList.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, doStaticListCommand);
var newContactList : ContextMenuItem = new ContextMenuItem("Add a New List");
newContactList.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, doNewStaticListCommand);
var removeContactList : ContextMenuItem = new ContextMenuItem("Remove contact from List");
removeContactList.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, doRemoveListCommand);
var deletecontact:ContextMenuItem = new ContextMenuItem("Delete contact");
deletecontact.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, dodeleteconactCommand);
var TimeList : ContextMenuItem = new ContextMenuItem("Add Time Spent");
TimeList.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, doTimeListCommand);
contextMenu.customItems.push(contactList);
contextMenu.customItems.push(newContactList);
contextMenu.customItems.push(deletecontact);
contextMenu.customItems.push(removeContactList);
In flex i done contex menu , if i rigt click then show context menu item but i want to hidden particular context menu item in list , is it possiable hidden and show particular items in context menu ? please refer me , i tried key value based
if(Application.application.contact_key==1)
{
contextMenu.customItems.push(deletecontact);
}
else
{
contextMenu.customItems.push(removeContactList);
}
contextMenu.customItems.push(TimeList);
return contextMenu;
Within itemRenderer
All coding on contactListItemRenderer.as and call to datagrid like
<mx:DataGridColumn itemRenderer="com.view.Contact.ContactListItemRenderer"
dataField="fullName" headerText="Full Name" />
You can access the custom menu items by contextMenu.customItem and hide/show any particular item. For the build in menu items you can access contextMenu.builtInItems (see the code below):
contextMenuCustom.builtInItems.zoom = false;
contextMenuCustom.builtInItems.save = true;

Resources