Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi too all

How can I add title to all links of menu that create with this code on c# ?
and the title I need is menu name and can I add h2 property to all link? if your answer is yes so please help me to do this.

C#
DataTable table = new DataTable();
        string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["awdbCS"].ConnectionString;
        SqlConnection conn = new SqlConnection(strCon);
        string sql = "select menu_id, menu_name, menu_parent_id, menu_url from menuMaster order by place";
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(table);
        DataView view = new DataView(table);
        view.RowFilter = "menu_parent_id = 0 ";
        foreach (DataRowView row in view)
        {
            MenuItem menuItem = new MenuItem(row["menu_name"].ToString(), row["menu_id"].ToString());
            menuItem.NavigateUrl = row["menu_url"].ToString();
            menuBar.Items.Add(menuItem);
            AddChildItems(table, menuItem);
Posted
Updated 27-Oct-14 22:56pm
v2

1 solution

Instead of passing first argument to MenuItem constructor as name of the menu you can pass as below to apply h2 header for it :-

C#
MenuItem menuItem = new MenuItem("<h2>" + row["menu_name"].ToString() + "</h2>", row["menu_id"].ToString());


This will display it as h2 header.

Not sure what do you mean by title here, as if you do as above it will display menu name as display text and id as value for it.If you mean by html tip to view on its hover then

C#
menuItem.ToolTip = "TitleText";


should work for you here.



Hope this will help you to proceed further.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900