Click here to Skip to main content
15,867,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

XML
<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>



help me to solve this thank u
Posted
Comments
Career Web Helper 29-Feb-12 5:49am    
user problem might be with "FontName".what is data type of FontName?
Nilesh Patil Kolhapur 29-Feb-12 6:13am    
varchar

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);
 
Share this answer
 
Comments
Nilesh Patil Kolhapur 29-Feb-12 6:13am    
there is not only single font name
Hi all,
I solved it using ItemDataBound event
C#
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
 
Share this answer
 
C#
<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>

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
C#
<asp:linkbutton id="runView1PerPage" font-names="Verdana, Arial" runat="server" xmlns:asp="#unknown"></asp:linkbutton>
 
Share this answer
 

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