C# 基于中继器内SqlDataSource中的数据更改Label控件属性

C# 基于中继器内SqlDataSource中的数据更改Label控件属性,c#,asp.net,sql-server,repeater,sqldatasource,C#,Asp.net,Sql Server,Repeater,Sqldatasource,我使用repeater控件将数据从SqlDataSource填充到自定义设计的显示框中 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnDataBinding="Repeater_ItemDataBound"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <div clas

我使用repeater控件将数据从SqlDataSource填充到自定义设计的显示框中

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnDataBinding="Repeater_ItemDataBound">
<HeaderTemplate>

</HeaderTemplate>

<ItemTemplate>

   <div class="bubble-content">
     <div style="float: left;">
       <h2 class="bubble-content-title"><%# Eval("CommentTitle") %></h2>
     </div>

     <div style="text-align: right;">
       <asp:Label ID="lbl_category" runat="server" Text=""><%# Eval("CommentType") %> 
       </asp:Label>
     </div>

     <div style="float: left;">
       <p><%# Eval("CommentContent") %></p>
     </div>
   </div>
</ItemTemplate>

<FooterTemplate>
</FooterTemplate>

</asp:Repeater>

<asp:SqlDataSource ID="mySqlDataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
    SelectCommand="SELECT [CommentTitle],[CommentType],[CommentContent] FROM [Comments] WHERE ([PostId] = @PostId)">
   <SelectParameters>
        <asp:QueryStringParameter Name="PostId" QueryStringField="id" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

现在,数据库中可以有三种类型的“CommentType”。我想根据[CommentType]的值更改“lbl_category”的CssClass属性

我试着这样做:

<asp:Label ID="lbl_category" runat="server" CssClass="<%# Eval("CommentType") %>" Text=""><%# Eval("CommentType") %></asp:Label>

但这会给出一个错误:“服务器控件的格式不正确”
我们还没有找到一种方法来实现这一点。有人能帮忙吗?

尝试从以下位置更改代码:

<asp:Label ID="lbl_category" runat="server" CssClass="<%# Eval("CommentType") %>" 


我已编辑了您的标题。请看“”,其中的共识是“不,他们不应该”。非常感谢,工作起来很有魅力:)它现在可以让我继续前进,但我想知道在C#中是否有同样的方法。就像我看到值是什么,然后相应地更改控件的属性。是的,看看OnItemBound事件。
<asp:Label ID="lbl_category" runat="server" CssClass='<%# Eval("CommentType") %>' />