2013-03-07 40 views
1

使用中继器显示列表,如果列表返回空白,表格将为空白,所以我显示了一个消息“表为空”,但我也想设置可见性表头为false,是否有属性?在中继器中设置标题为visible.false

repeater.header什么的?

感谢


编辑:对于那些谁暗

<asp:Repeater id="rptSelectedUtilities" runat="server"> 
    <HeaderTemplate> 
     <table class="detailstable FadeOutOnEdit"> 
      <tr> 
       <th style="width:200px;">Utility</th>  
       <th style="width:200px;">Contacted</th> 
       <th style="width:200px;">Comment</th>  
      </tr> 
    </HeaderTemplate> 
    <ItemTemplate> 
      <tr> 
       <th style="width:200px;"><%# Eval("Name") %></th> 
       <th style="width:200px;"><asp:CheckBox ID="chkMyCheck" runat="server" Checked='<%# Convert.ToBoolean(Eval("Checked")) %>'/></th> 
       <th style="width:200px;"><%# Eval("Comment") %></th> 
      </tr> 
      <asp:Label id="labelTableEmpty" runat="server" Text="There are currently no items in this table." /> 
    </ItemTemplate> 
    <FooterTemplate> 
      <asp:Label id="labelTableEmpty" runat="server" Text="There are currently no items in this table." /> 
     </table> 
    </FooterTemplate> 
</asp:Repeater> 

感谢不能计划的任何帮助

+0

发布您的代码 - 我们正在编程盲目。 – 2013-03-07 11:44:19

+0

请参阅编辑 – John 2013-03-07 11:47:15

+0

谢谢约翰,但要小心你的态度,请记住,我们正在帮助你***免费,因为***你不知道该怎么做。当你写一个问题时,从我们的角度考虑这个问题。有足够的信息来解决它吗?因为我们不知道你想做什么,而且我们也不知道你已经做了什么。 – 2013-03-07 11:52:06

回答

2

好吧,让我们改变了这一点。我们将使整个转发器不可见,然后添加另一个标签来标记,并在必要时使其可见。这种替换中继代码:

<asp:Repeater id="rptSelectedUtilities" runat="server"> 
    <HeaderTemplate> 
     <table class="detailstable FadeOutOnEdit"> 
      <tr> 
       <th style="width:200px;">Utility</th>  
       <th style="width:200px;">Contacted</th> 
       <th style="width:200px;">Comment</th>  
      </tr> 
    </HeaderTemplate> 
    <ItemTemplate> 
      <tr> 
       <th style="width:200px;"><%# Eval("Name") %></th> 
       <th style="width:200px;"><asp:CheckBox ID="chkMyCheck" runat="server" Checked='<%# Convert.ToBoolean(Eval("Checked")) %>'/></th> 
       <th style="width:200px;"><%# Eval("Comment") %></th> 
      </tr> 
    </ItemTemplate> 
    <FooterTemplate> 
     </table> 
    </FooterTemplate> 
</asp:Repeater> 

,然后转发后添加这个(当然你也可以改变措辞):

<asp:Label id="labelTableEmpty" runat="server" Text="There are currently no items in this table." /> 

,然后在OnPreRender在Web表单我们要编写一些代码:

protected override void OnPreRender(EventArgs e) 
{ 
    if (rptSelectedUtilities.Items.Count == 0) 
    { 
     rptSelectedUtilities.Visislbe = false; 
     labelTableEmpty.Visible = true; 
    } 
    else 
    { 
     rptSelectedUtilities.Visislbe = true; 
     labelTableEmpty.Visible = false; 
    } 
} 
+0

干杯迈克,工作很好 – John 2013-03-07 12:21:17

+0

谢谢约翰,我是很高兴我可以帮助! – 2013-03-07 12:21:33