Default text for empty Repeater control

前端 未结 8 1002
醉梦人生
醉梦人生 2021-02-02 05:43

Using VS 2008, I have a Repeater control:



        
相关标签:
8条回答
  • 2021-02-02 06:32

    You could workaround the fact that Repeater does not support a inbuilt way to accomplish what you are doing by using the FooterTemplate in conjunction with the OnItemDataBound event and showing the footer only when the data source returns no items.

    Examples on how you can do this can be found at:

    Handling Empty Data in an ASP.NET Repeater control

    How to show Empty Template in ASP.NET Repeater control?

    0 讨论(0)
  • 2021-02-02 06:35

    You can use a footer template to manage massage, like this

    Step 1

    <FooterTemplate>
        <%-- Label used for showing Error Message --%>
        <asp:Label ID="lblDefaultMessage" runat="server" Text="Sorry, no item is there to show." Visible="false">
        </asp:Label>
    </FooterTemplate> 
    

    Step 2

    Handle visibility of lable in Repeater_ItemDataBound event like

    protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
     if (Repeater.Items.Count < 1)
      {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            Label lblDefaultMessage= (Label)e.Item.FindControl("lblDefaultMessage");
            lblDefaultMessage.Visible = true;
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题