如何在c#上为此菜单代码的链接添加tilte [英] how to add tilte to links of this menu code on c#

查看:94
本文介绍了如何在c#上为此菜单代码的链接添加tilte的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧



如何在c#上使用此代码创建的所有菜单链接添加标题?

和我需要的标题是菜单名称,我可以在所有链接中添加h2属性吗?如果你的回答是肯定的,那么请帮助我这样做。



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.

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);

推荐答案

而不是将第一个参数作为菜单名称传递给MenuItem构造函数,而不是通过以下方式为它应用h2标题: -



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

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





这将显示为h2标题。



不确定这里的标题是什么意思,就像你上面那样,它会显示菜单名称作为显示文本,id显示为它的值。如果你的意思是通过html提示来查看它的悬停,那么





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

menuItem.ToolTip = "TitleText";





应该适合你。







希望这会帮助您继续前进。



should work for you here.



Hope this will help you to proceed further.


这篇关于如何在c#上为此菜单代码的链接添加tilte的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆