c# - CSS 不在转发器内格式化

标签 c# css asp.net

我正在尝试在转发器中使用 css。当我运行它时,没有格式。但是,当我在中继器外使用 css 时,它的格式很好。

<style>
   body {
       background-color:lightgray
   }
   .messageBox p  {
        background-color:white;
        width: 25%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
   }
</style>

外部中继器

<div class="messageBox">
  <p>The quick brown fox jumped over the lazy dog</p>
  <p>The quick brown fox jumped over the lazy dog</p>
  <p>The quick brown fox jumped over the lazy dog</p>
  <p>The quick brown fox jumped over the lazy dog</p>
  <p>The quick brown fox jumped over the lazy dog</p>
</div>

中继器内部

<asp:Repeater ID="myRepeater" runat="server">
    <ItemTemplate>
        <br />
        <div class="messageBox">
            <p>
                <%# Eval("Message") %>                            
            </p>
        </div>
    </ItemTemplate>
</asp:Repeater>

最佳答案

你需要移动<div class="messageBox">HeaderTemplate或在中继器和关闭之前 </div>FooterTemplate或者在转发器的末尾。

最终结果应该是这样的:

<asp:Repeater ID="myRepeater" runat="server">
    <HeaderTemplate>
        <div class="messageBox">
    </HeaderTemplate>
    <ItemTemplate>
        <br />
        <p>
            <%# Eval("Message") %>                            
        </p>
    </ItemTemplate>
    <FooterTemplate>
        </div>
    </FooterTemplate>
</asp:Repeater>

或:

<div class="messageBox">
    <asp:Repeater ID="myRepeater" runat="server">       
        <ItemTemplate>
            <br />
            <p>
                <%# Eval("Message") %>                            
            </p>
        </ItemTemplate>     
    </asp:Repeater>
</div>

我喜欢第一种方法,因为它不会留空 div如果没有数据元素。

关于c# - CSS 不在转发器内格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53763306/

相关文章:

c# - 如何 : handle exceptions, 最佳实践

asp.net - 如何查询强类型数据表

asp.net - 没有文本时标签周围的边框

c# - 调用异步订单

c# - 拥有信用卡模型安全吗?

javascript - 悬停在父元素上时,显示子元素(下拉导航)

javascript - 在样式表中指定多 css 类

c# - Entity Framework 更新记录问题(无法调用成员 'IsModified' 获取属性)

c# - 计算服务区域的最有效方法 Asp.net + SQL Server

html - 二级菜单 - 二级菜单不出现