I'm a beginner (and not a really good english-speaker :) ), and i want to bind my sitemapdatasource to an asp accordion.
Its works well with two levels but it doesn't works with the third level
I tried this :
accordion 1
header container
first level
accordion 2
header container
second level
content container
third level
I have something like :
menu 1
menu 1.1
menu 1.2
menu 2
...
and in the other accordion
menu 1.1.1 menu 1.1.2...
menu 2.1.1 menu 2.1.1
I read a lot of threads about this so i just want to know if my example should works (if i just need to fix the code, would be better if i fix it by myself), or if my idea sucks and i need o find an other way to resolve this issue
MasterPage.master
<ajaxToolkit:Accordion ID="myAccordion" runat="server" SuppressHeaderPostbacks="true" >
</ajaxToolkit:Accordion>
<ajaxToolkit:Accordion ID="myAccordion1" runat="server" SuppressHeaderPostbacks="true" >
</ajaxToolkit:Accordion>
MasterPage.master.cs (in the page_load)
for (int i = 0; i < SiteMap.RootNode.ChildNodes.Count; i++)
{
//GRABS SITEMAP MAIN ITEMS (UNDER HOME)
SiteMapNode smn = (SiteMapNode)SiteMap.RootNode.ChildNodes[i];
//CREATES ACCORDION PANE
AjaxControlToolkit.AccordionPane p = new AjaxControlToolkit.AccordionPane();
//CREATE UNIQUE PANE ID
p.ID = "Pane" + i;
//CREATE HEADER ITEM
HyperLink hlHeader = new HyperLink();
hlHeader.NavigateUrl = SiteMap.RootNode.ChildNodes[i].Url.ToString();
hlHeader.Text = SiteMap.RootNode.ChildNodes[i].Title.ToString();
//ADDS HEADER LINK TO PANE (HEADER)
p.HeaderContainer.Controls.Add(hlHeader);
//CHECKS IF HEADER ITEM HAS CHILDREN
if (smn.HasChildNodes)
{
AjaxControlToolkit.AccordionPane psub = new AjaxControlToolkit.AccordionPane();
psub.ID = "Panel" + i;
//CREATE BULLETED LIST OF CHILDREN
BulletedList blMenu = new BulletedList();
blMenu.DisplayMode = BulletedListDisplayMode.HyperLink;
//CREATES LIST ITEMS WITHIN BULLETED LIST FOR CHILDREN
for (int j = 0; j < smn.ChildNodes.Count; j++)
{
blMenu.Items.Insert(0, (new ListItem(smn.ChildNodes[j].Title.ToString(), smn.ChildNodes[j].Url.ToString())));
HyperLink hlSubHeader = new HyperLink();
hlSubHeader.NavigateUrl = smn.ChildNodes[j].Url.ToString();
hlSubHeader.Text = smn.ChildNodes[j].Title.ToString();
psub.HeaderContainer.Controls.Add(hlSubHeader);
BulletedList blSubMenu = new BulletedList();
blSubMenu.DisplayMode = BulletedListDisplayMode.HyperLink;
for (int k = 0; k < smn.ChildNodes[j].ChildNodes.Count; k++)
{
blSubMenu.Items.Insert(0, (new ListItem(smn.ChildNodes[j].ChildNodes[k].Title.ToString(), smn.ChildNodes[j].ChildNodes[k].Url.ToString())));
}
psub.ContentContainer.Controls.Add(blSubMenu);
myAccordion1.Panes.Add(psub);
}
//ADDS BULLETED LIST TO PANE (CONTAINER)
p.ContentContainer.Controls.Add(blMenu);
}
//ADDS PANE TO ACCORDION
myAccordion.Panes.Add(p);
}
Thanks
Related
Basically I'm making a program that allows you to add to a stackpanel another stackpanel with several horizontally aligned textboxes with the press of a button. So far, everything is working as intented. Here's my code so far ,Stacker is the name of the parent stackpanel and it starts off empty:
private void Add_Click(object sender, RoutedEventArgs e)
{
Stacker.Children.Add(NewXD(Stacker.Children.Count + 1));
}
public System.Windows.Controls.StackPanel NewXD(int XD)
{
System.Windows.Controls.StackPanel NewP = new StackPanel();
NewP.Orientation = Orientation.Horizontal;
System.Windows.Controls.TextBox HAHA = new TextBox();
HAHA.Name = "question" + XD.ToString();
//HAHA.Text = HAHA.Height.ToString()+" "+HAHA.Width.ToString();
HAHA.Height = Double.NaN;
HAHA.Width = 120;
HAHA.FontSize=20;
NewP.Children.Add(HAHA);
for (int i = 1; i < 6; i++)
{
System.Windows.Controls.TextBox newBox = new TextBox();
newBox.Name = "answer"+XD.ToString()+"_"+i.ToString();
newBox.Height = Double.NaN;
newBox.Width = 120;
NewP.Children.Add(newBox);
}
System.Windows.Controls.ComboBox correct = new ComboBox();
correct.Name = "correct" + XD.ToString();
for (int i = 1; i < 6; i++)
{
System.Windows.Controls.ComboBoxItem newItem = new ComboBoxItem();
newItem.Name = "ans" + XD.ToString() + "_" + i.ToString();
newItem.Content = i.ToString();
correct.Items.Add(newItem);
}
NewP.Children.Add(correct);
return NewP;
}
I apologize for the lack of seriousness in some of my code.
Now, what I need to do is for the child stackpanels to also contain independent file pickers that work like the one sampled in this thread: Open file dialog and select a file using WPF controls and C#
What I don't know how to perform is that each of these generated buttons have the same basic funcion but are linked with each of their corresponding textbox.
Thanks in advance :)
Edit: As I was writing this it occured to me that perhaps I could use the help of the child stackpanel's array-like properties to choose the corresponding textbox, because the file selector's textbox and button will always be the last two items in the stackpanel, but I'm not very sure how to perform this.
For functionality you can create an EventHandler that will be assigned to each button. Your event handler will then open File Dialog...
Buttons have Tag property which you could use to identify your TextBoxes, or you could derive from Button class and add AssociatedTextBox property for example.
I have a ToolStripMenuItem I need to check if it has a sub menu with a particular name, if it exists, add a new menu item to that sub menu, and if not, create the sub menu and add the item to the new sub menu.
ToolStripItemCollection menu = tsmi1.DropDownItems;
for(int i = 0; i < menu.Count; i++) {
if(item.Category.Equals(menu[i].Text)) {
menu[i]. //need to add new menu item here....
}
}
It may just be that I don't understand how the menu system actually works, but it appears I can't add an item to my menu object.
Is your sub-menu a ToolStripDropDownItem?
The objects in TooLStripItemCollection are all of type ToolStripItem. You may need to cast the item you find to the derived class, ToolStripDropDownItem.
That will give you access to its DropDownItems collection, which is another ToolStripItemCollection and has Add, AddRange, and Insert methods.
I haven't worked with ToolStripDropDownItem myself, but that's the path I'd start on.
Edit by bwoogie:
Final code:
ToolStripMenuItem tsmi = new ToolStripMenuItem();
tsmi.Text = item.Name;
tsmi.Click += node_Click;
ToolStripItemCollection nodeMenu = nodesToolStripMenuItem.DropDownItems;
for (int i = 0; i < nodeMenu.Count; i++) {
if (item.Category.Equals(nodeMenu[i].Text)) {
((ToolStripMenuItem)nodeMenu[i]).DropDownItems.Add(tsmi);
} else {
ToolStripItem newtsi = nodeMenu.Add(item.Category);
((ToolStripMenuItem)newtsi).DropDownItems.Add(tsmi);
}
}
I'm still working on getting a menu to display all of the input devices on a computer- pardon my third question in something that is probably very simple.
Here's the code:
List<MenuItem> inputDevice = new List<MenuItem>();
MenuItem myMenuItemInputDevices = new MenuItem("&Input Devices");
sgFileMenu.MenuItems.Add(myMenuItemInputDevice);
for (int i = 0; i < DeviceCount; i++)
{
inputDeviceMenu.Add(new MenuItem(inputName[i]));
myMenuItemInputDevices.MenuItems.Add(inputDeviceMenu[i]);
myMenuItemInputDevices.Click += new System.EventHandler(this.myMenuItemInputDeviceClick);
}
This seems to work just fine, the menu items are added, everything is good, but clicks on the dropdown list are not working. I've done other work with menus, and clicks in other code are working correctly. I tried putting
myMenuItemInputDevices.Click += new System.EventHandler(this.myMenuItemInputDeviceClick);
outside of the {}, just in case that was the right way to do it, but that didn't help.
What am I missing?
You want this
List<MenuItem> inputDevice = new List<MenuItem>();
MenuItem myMenuItemInputDevices = new MenuItem("&Input Devices");
sgFileMenu.MenuItems.Add(myMenuItemInputDevice);
for (int i = 0; i < DeviceCount; i++)
{
inputDeviceMenu.Add(new MenuItem(inputName[i]));
inputDeviceMenu[i].Click += new System.EventHandler(this.myMenuItemInputDeviceClick);
myMenuItemInputDevices.MenuItems.Add(inputDeviceMenu[i]);
myMenuItemInputDevices.Click += new System.EventHandler(this.myMenuItemInputDeviceClick);
}
EDIT: It is pretty obvious that the Menu Items that you are trying to add does not have any Click event method hooked up.
inputDeviceMenu.Add(new MenuItem(inputName[i]));
You are just adding them.
I am adding the dynamically TextBox in the placeholder on the button click in that.
When all the textboxes are loaded I am making changes in the values and again Press another Button to save the values to the SharePoint List. But when I press the Save button and I checked the placeholder by debugging it I found that there were no any control in the placeholder.
I am adding the Controls like follows :
TextBox[] tb = new TextBox[item_ans.Count];
Literal[] lt = new Literal[item_ans.Count];
for (int j = 0; j < item_ans.Count; j++)
{
ans_id.Add(item_ans[j]["ID"].ToString());
tb[j] = new TextBox();
tb[j].ID = "tb_ans" + (j + 1).ToString();
tb[j].Text = item_ans[j]["Title"].ToString();
lt[j] = new Literal();
lt[j].Text = "<br/>";
pl_hd_ans.Controls.Add(tb[j]);
pl_hd_ans.Controls.Add(lt[j]);
}
And on the Save Button click I am Retrieving those TextBoxes Like follows:
int n = Convert.ToInt32(ViewState["totalAns"].ToString());
foreach (var i in ans_id)
{
var item_ans = list_ans.GetItemById(i);
clientContext.Load(item_ans);
clientContext.ExecuteQuery();
for (int k = 0; k < n; k++)
{
TextBox tb = (TextBox)pl_hd_ans.FindControl("tb_ans" + (k + 1).ToString());
item_ans["Title"] = tb.Text;
item_ans.Update();
clientContext.Load(item_ans);
clientContext.ExecuteQuery();
}
}
But in this I check the Placeholder's Controls that were 0. Can Any one please help me to solve this..?
I'm assuming its ASP.NET WebForms what we're talking about here.
When you are adding controls dynamically to the webpage, you have to recreate them on each sequential postback. The reason for this, is that the dynamically created controls are not present in the .aspx file, nor in the viewstate, so asp.net cannot know that it has to recreate these controls. Therefore, you yourself have to recreate them in the initialized-event (before the page-load), including adding any event handlers that you need.
You can google about it.
I am trying to find how I can add items to devExpress PopupMenu. I have tried the following:
manager = new BarManager();
listBoxMenu = new PopupMenu(manager);
listBoxMenu.ItemLinks.Add(manager.Items["Remove item"]);
listBoxMenu.ItemLinks.Add(manager.Items["Clear items"]);
As shown here http://documentation.devexpress.com/#WindowsForms/CustomDocument5472 (at the bottom), but it gives me an error saying the item is not initialized.
What is the proper way to add items? I can't find it anywhere.
Edit, here is how I did it:
//Creates the popup menu to be used for the keywords listbox
manager = new BarManager();
listBoxMenu = new PopupMenu(manager);
item = new BarButtonItem(manager, "Copy");
item2 = new BarButtonItem(manager, "Clear Item");
item3 = new BarButtonItem(manager, "Clear All Items");
listBoxMenu.ItemLinks.Add(item);
listBoxMenu.ItemLinks.Add(item2);
listBoxMenu.ItemLinks.Add(item3);
//Adds the seperator on the second item
item2.Links[0].BeginGroup = true;
manager.ItemClick += manager_ItemClick;
Check this code snippet and implement using the same way.
//create popup and manage objects
private DevExpress.XtraBars.BarManager barManager1;
private DevExpress.XtraBars.PopupMenu buttonContextMenu;
DevExpress.XtraBars.BarButtonItem menuButtonExport = new DevExpress.XtraBars.BarButtonItem();
DevExpress.XtraBars.BarButtonItem menuButtonSave = new DevExpress.XtraBars.BarButtonItem();
public TestForm8()
{
InitializeComponent();
barManager1 = new BarManager();
this.barManager1.Form = this;
buttonContextMenu = new DevExpress.XtraBars.PopupMenu(barManager1);
this.buttonContextMenu.Name = "subViewContextMenu";
menuButtonExport.Caption = "E&xport";
menuButtonExport.Id = 1;
menuButtonExport.Name = "menuButtonExport";
menuButtonExport.ItemClick += new ItemClickEventHandler(menuButtonExport_ItemClick);
menuButtonSave.Caption = "S&ave";
menuButtonSave.Id = 2;
menuButtonSave.Name = "menuButtonSave";
menuButtonSave.ItemClick += new ItemClickEventHandler(menuButtonSave_ItemClick);
//add items to barmanager
this.barManager1.Items.AddRange(new DevExpress.XtraBars.BarItem[] {
menuButtonExport,
menuButtonSave
});
//create links between bar items and popup
buttonContextMenu.ItemLinks.Add(barManager1.Items["menuButtonExport"]);
buttonContextMenu.ItemLinks.Add(barManager1.Items["menuButtonSave"]);
//finally set the context menu to the control or use the showpopup method on right click of control
barManager1.SetPopupContextMenu(btnInsert, buttonContextMenu);
}
Ref by step to include popup:
How to: Create a popup menu
How to: Add items to a container bar item (menu)
Populating Popup Menus
BarManager.SetPopupContextMenu Method
Your manager is empty:
manager = new BarManager();
The example you linked to is using a BarManager that was already created: barManager1, which I assume was created in the designer and populated with items.
From their BarManager help page:
After a BarManager has been added to a form/user control, you can create bars and bar commands using context menus right on the form, using the bar manager's Customization Window or its Designer. Please see the Toolbars Customization section, to learn more.