I have a label in a gridview, and I want to put an awesome icon font inside the label according to the value of a field, my code is:
<asp:Label runat="server" Text='<%# string.Format("<i class='fa fa-{0}'></i>", Eval("[TypeIconFF]")) %>' EncodeHtml="false" />
But it gives me an exception of type System.Web.HttpException (Wrong server label)
I think the error may be generated by single quotation marks
Does anyone have any idea how to solve it?
Thanks in advance
Try:
<asp:Label ID="Label2" runat="server"
Text='<%# $@"<i class=""fa fa-{Eval("TypeIconFF")}""></i>" %>'
>
</asp:Label>
Not sure if you need the [], but then this:
<asp:Label ID="Label2" runat="server"
Text='<%# $@"<i class=""fa fa-{Eval("[TypeIconFF]")}""></i>" %>'
>
</asp:Label>
you also should not need the html encode option.
So, with this grid:
I also like the fa-lg (larger).
So this gv:
<asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="true"
AutoGenerateColumns="False" DataKeyNames="ID" CssClass="table table-hover" Width="52%">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="HotelName" HeaderText="HotelName" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# $@"<i class=""fa fa-{Eval("FA")} fa-lg""></i>" %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And code :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = General.MyRst("SELECT * FROM tblhotelsA");
GridView1.DataBind();
}
}
and I get/see this: