将字体名称设置为链接按钮时出错 [英] Error when set font name to link button

查看:89
本文介绍了将字体名称设置为链接按钮时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


当我在运行时将字体名称绑定到linkbutton时,以下错误显示


无法将类型为"System.String"的对象转换为类型为"System.String []".

我的代码

Hi,
when i bind fontname to linkbutton on run time then following error shows


Unable to cast object of type ''System.String'' to type ''System.String[]''.

my code

<asp:LinkButton ID="lnkMenu" runat="server" Font-Names='<%#Eval("FontName")%>' Font-Size='<%#Convert.ToInt32(Eval("FontSize")) %>' Text='<%#Eval("Name")%>' CommandArgument='<%#Eval("ID") %>'

                                                                    ToolTip="Select" OnClick="Repeater_Click">
                                                                </asp:LinkButton>




帮我解决这个问题u




help me to solve this thank u

推荐答案

Take a hidden field and bind that with <%#Eval("FontName")%>

then in rowdatabind event

         LinkButton lnk=(LinkButton)....FindControl("lnkMenu");
         HtmlInputHidden fn=(HtmlInputHidden)....FindControl("hdnFontFamily");
         lnk.Style.Add("Font-Names", fn.Value);


大家好,
我使用ItemDataBound事件
Hi all,
I solved it using ItemDataBound event
protected void reptrDisplay_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem && e.Item.ItemType != ListItemType.Header)
        {

            LinkButton lnkMenu = (LinkButton)e.Item.FindControl("lnkMenu");
            lnkMenu.Enabled = Modify;
            string[] detail = lnkMenu.CommandArgument.ToString().Split(';');
            
            lnkMenu.Font.Name = detail[1];
            lnkMenu.Font.Size = int.Parse(detail[2]);
        }
    }



谢谢您的支持



Thnks for ur support


<asp:linkbutton id="lnkMenu" runat="server" fontnames="<%#Eval("FontName")%>" font-size="<%#Convert.ToInt32(Eval("FontSize"))%>" text="<%#Eval("Name")%>" commandargument="<%#Eval("ID") %>" tooltip="Select" onclick="Repeater_Click" xmlns:asp="#unknown">                                                               </asp:linkbutton>


问题出在您的代码中,您正在将集合分配给字符串,例如font1,font2,.. etc到Font Names属性,所以它给出了类似
的错误 无法将类型为"System.String"的对象转换为类型为"System.String []""
请参阅


the problem is in ur code,u are assigning collection to strings ie.font1,font2,..etc to Font Names property,so it gives error like
"Unable to cast object of type ''System.String'' to type ''System.String[]''"
refer

<asp:linkbutton id="runView1PerPage" font-names="Verdana, Arial" runat="server" xmlns:asp="#unknown"></asp:linkbutton>


这篇关于将字体名称设置为链接按钮时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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