我有一个网格视图,我试图从包含HTML代码的数据库字符串中设置前颜色。我试过这个:
<asp:TemplateField HeaderText="Validation">
<ItemTemplate>
<asp:Label ID="lblValidationItem" runat="server" ToolTip="Type of validation."
Text='<%# DataBinder.Eval(Container, "DataItem.ValidationItem") %>' Font-Bold="true" ForeColor='<%# System.Drawing.ColorTranslator.FromHtml(Eval("HTMLColor")) %>'></asp:Label>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
但它说FromHtml有一些无效的参数?
答案 0 :(得分:2)
Eval返回“对象”。您需要将其强制转换为字符串:
<ItemTemplate>
<asp:Label ID="lblValidationItem" runat="server" ToolTip="Type of validation."
Text='<%# Eval("DataItem.ValidationItem") %>' Font-Bold="true" ForeColor='<%# System.Drawing.ColorTranslator.FromHtml((string)Eval("HTMLColor")) %>'></asp:Label>
</ItemTemplate>