+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / ForumList.ascx and EmptyDataTemplate

ForumList.ascx and EmptyDataTemplate

6 posts, 1 answered
  1. Eric Marthinsen
    Eric Marthinsen avatar
    12 posts
    Registered:
    20 Jun 2005
    28 Oct 2010
    Link to this post
    Hello-

    I modified the ForumList.ascx in SiteFinity/ControlTemplates/Forum to tweak the design of the list of forums. What I'm trying to do now is add in the EmptyDataTemplate so there will be a friendly message if there are no active forums. Here's my code for the forums repeater:

    <asp:Repeater ID="forumsRepeater" runat="server">
        <HeaderTemplate>
     
        </HeaderTemplate>
        <ItemTemplate>
            <h2 class="sf_forumCategoryTitle"><%#DataBinder.Eval(Container.DataItem, "Name")%></h2>
            <asp:GridView ID="inner" runat="server" CssClass="sf_forumsList" AutoGenerateColumns="false" GridLines="none">
                <Columns>
                    <asp:TemplateField HeaderText="<%$Resources:Status %>" Visible="false">
                        <ItemTemplate>
                            <asp:Literal ID="forumStatus" runat="server"></asp:Literal>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="<%$Resources:Forum %>">
                        <ItemTemplate>
                            <asp:LinkButton ID="btnOpenForum" runat="server"></asp:LinkButton>
                            <div><asp:Literal id="lblDescription" runat="server"></asp:Literal></div>
                        </ItemTemplate>
                        <ItemStyle CssClass="sf_forumTitle" />
                    </asp:TemplateField>
                     
                    <asp:BoundField DataField="PostsCount" HeaderText="<%$Resources:Posts %>" />
                    <asp:BoundField DataField="ThreadsCount" HeaderText="<%$Resources:Threads %>" />
                    <asp:TemplateField HeaderText="<%$Resources:LastPost %>" HeaderStyle-CssClass="sf_forumAuthor">
                        <ItemTemplate>
                            <asp:LinkButton ID="goToPost" runat="server" CausesValidation="false"><sfWeb:DateTimeLiteral ID="lastPostDate" runat="server" DateFormatString="dd MMM yyyy, hh:mm"></sfWeb:DateTimeLiteral></asp:LinkButton>
                            <asp:Label ID="noPosts" runat="server" Text="<%$Resources:NoPosts %>"></asp:Label>
           
                            <asp:Label ID="byText" runat="server" Text="By "></asp:Label>
                            <prof:ManageProfile ID="lastPostAuthor" runat="server" ShowAnonymousLabel="true" AnonymousLabel="<%$ Resources:Anonymous %>">
                                <ViewTemplate>
                                    <asp:Literal ID="FirstName" runat="Server"></asp:Literal
                                    <asp:Literal ID="LastName" runat="Server"></asp:Literal>
                                </ViewTemplate>
                            </prof:ManageProfile>
                        </ItemTemplate>
                        <ItemStyle CssClass="sf_forumAuthor" />
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate>
                    There are no forums to display.
                </EmptyDataTemplate>
            </asp:GridView>
        </ItemTemplate>
        <FooterTemplate>
             
        </FooterTemplate>
    </asp:Repeater>


    Does anyone know how to get my friendly message to display?

    Regards,
    Eric
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Oct 2010
    Link to this post
    Hello Eric,

    Check if there are Rows in the GridView . If there are no rows, then show your message.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Eric Marthinsen
    Eric Marthinsen avatar
    12 posts
    Registered:
    20 Jun 2005
    28 Oct 2010
    Link to this post
    Hi Ivan-

    Do you have a code sample I can use to get rolling? Are you recommending I do some client-side post-processing using JQuery, or is there an event I can hook into to handle this server-side?

    Regards,
    Eric
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Oct 2010
    Link to this post
    Hello Eric,

    Try using inner.Rows.Count on the server. You can get the GridView control from ItemDataBound event of forumsRepeater where you can call forumsRepeater.FindControl("inner") as GridView;

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Eric Marthinsen
    Eric Marthinsen avatar
    12 posts
    Registered:
    20 Jun 2005
    28 Oct 2010
    Link to this post
    Hi Ivan-

    I think we're getting close. I did what you recommended. I added this code to the ItemDataBound event of the forumRepeater control:

    //see if we should be displaying the "no forums" message
    GridView inner = this.forumsRepeater.FindControl("inner") as GridView;
              
    if(inner == null || inner.Rows.Count == 0)
    {
        Panel pnlNoForums = this.forumsRepeater.FindControl("pnlNoForums") as Panel;
      
        if (pnlNoForums != null)
            pnlNoForums.Visible = true;
    }

    The problem is that whenever the code runs, the variable "inner" is always null. Any ideas?

    Also, as an FYI, pnlNoForums is a sibling of inner.

    Regards,
    Eric
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Nov 2010
    Link to this post
    Hi Eric ,

    There are two GridView controls which you can access as the sample below illustrates

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.forumsRepeater.ItemDataBound += new RepeaterItemEventHandler(forumsRepeater_ItemDataBound);
        }
     
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (this.Uncategorized.Rows.Count > 0)
            {
     
            }
        }
     
    void forumsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            var g = e.Item.FindControl("inner") as GridView;
            if (g != null)
            {
                 
            }
        }
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
Register for webinar
6 posts, 1 answered