Click here to Skip to main content
11,633,998 members (74,959 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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>


help me to solve this thank u
Posted 28-Feb-12 23:30pm
Comments
RockingDev at 29-Feb-12 5:49am
   
user problem might be with "FontName".what is data type of FontName?
Patil_Nilesh at 29-Feb-12 6:13am
   
varchar
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
  Permalink  
Comments
Patil_Nilesh at 29-Feb-12 6:13am
   
there is not only single font name
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 OriginalGriff 8,758
1 Sergey Alexandrovich Kryukov 8,264
2 Mika Wendelius 6,755
3 F-ES Sitecore 2,344
4 Suvendu Shekhar Giri 2,095


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 7 Mar 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100