I am useing the code below for a menu but where the item1, item2.. is I would like to have a linkbutton apear when displayed in the bullets. Any code I place in quotes will show the code on the page and not my intended resoults. Please point me in the right direction.
String[] mainmenuitems = { "item1",
"item2",
"item3"};
BulletedList MenuBulletedList1 = new BulletedList();
MenuBulletedList1.Items.Add(mainmenuitems[0]);
MenuBulletedList1.Items.Add(mainmenuitems[1]);
MenuBulletedList1.Items.Add(mainmenuitems[2]);
ContentUpperLeftBlock.Controls.Add(MenuBulletedList1);
ContentUpperLeftSmallTextLabel.Text = "Main menu";
Thanks for any help in advance,
David
Loading
Javeed M ShaikhPosted Oct 23, 2011, 9:02 PM
string mValue = string.Empty;
for (int i = 0; i < mainmenuitems.GetLength(0); i++)
{
for (int j = 0; j < mainmenuitems.GetLength(1); j++)
{
mText = mainmenuitems[i, j];
mValue = mainmenuitems[i, ++j];
}
ls1 = new ListItem(mText,mValue);
MenuBulletedList1.Items.Add(ls1);
}
David RockafellowPosted Oct 23, 2011, 9:09 PM
David RockafellowPosted Oct 23, 2011, 8:17 PM
string[,] mainmenuitems = new string[2, 2] { { "link1", "http://me.com" }, { "link2", "http://me.com" } };
BulletedList MenuBulletedList1 = new BulletedList();
MenuBulletedList1.DisplayMode = BulletedListDisplayMode.HyperLink;
ListItem ls1 = null;
foreach (string item in mainmenuitems)
{
ls1 = new ListItem(item,"XX");
MenuBulletedList1.Items.Add(ls1);
}
ContentUpperLeftBlock.Controls.Add(MenuBulletedList1);
MenuBulletedList1.Visible = true;
ContentUpperLeftSmallTextLabel.Text = "Main menu";
Javeed M ShaikhPosted Oct 23, 2011, 7:50 PM
BulletedList MenuBulletedList1 = new BulletedList();
MenuBulletedList1.DisplayMode = BulletedListDisplayMode.HyperLink;
ListItem ls1 = null;
foreach (string item in mainmenuitems)
{
ls1 = new ListItem(item,"http://www.microsoft.com/");
MenuBulletedList1.Items.Add(ls1);
}
PlaceHolder1.Controls.Add(MenuBulletedList1);
David RockafellowPosted Oct 23, 2011, 7:44 PM
Thank you for the responce. I do have DisplayMode set, where I seem to be stuck on is how to pass the Value="link" and the caption in from behind the scenes. I'm passing in the caption fine but not the value for the link. Did that make more sense?
Thanks again,
David
Javeed M ShaikhPosted Oct 23, 2011, 7:27 PM
try to create a ListItem and than add the same to the bulleted List, like this (the attribute in bold is important to display the items as hyperlink, you can add this attribute in your code and check the output):
ID="BulletedList1"
runat="server">
Please do not forget to mark "Accepted Answer".