Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Message Board comment counting View modes: 
User avatar
Member
Member
rdiepenbrock - 8/31/2009 2:49:05 PM
   
Message Board comment counting
Concerning the message board web part and functionality, how would I count the comments written to a page and display them?

Thanks,
Richard

User avatar
Member
Member
rdiepenbrock - 9/1/2009 9:22:09 AM
   
RE:Message Board comment counting
Would this be similar to counting vote totals in the polls?
An OnExternalDataBound property?

Thanks,
Richard

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 9/1/2009 10:11:13 AM
   
RE:Message Board comment counting
Hello,

You can use slightly modified approach as it is described in one KB article here: http://devnet.kentico.com/Knowledge-Base/Web-parts---Controls/How-to-display-number-of-records-in-repeater.aspx

Basically you just need to count items in repeater used within Message Board control: ~\CMSModules\MessageBoards\Controls\MessageBoard.ascx.cs

Please add following code to the ReloadBoardMessages() method just after repeater's data bind call like this:

this.rptBoardMessages.DataBinding += new EventHandler(rptBoardMessages_DataBinding);


And create new method like this:

    void rptBoardMessages_DataBinding(object sender, EventArgs e)
{
if (!CMS.GlobalHelper.DataHelper.DataSourceIsEmpty(rptBoardMessages.DataSource))
{
System.Data.DataSet dv = rptBoardMessages.DataSource as System.Data.DataSet;
if (dv != null)
{
ltlRepeaterCount.Text = dv.Tables[0].Rows.Count.ToString();
}
}
}


Then you can just add label control to the HTML code to show up the number:

<asp:Label ID="ltlRepeaterCount" runat="server" ></asp:Label>


Best Regards
Ondrej Vasil

User avatar
Member
Member
rdiepenbrock - 9/1/2009 2:37:20 PM
   
RE:Message Board comment counting
Thanks, that worked.

Here's one more question: how do you change the sorting direction of the posts? By default, they post oldest to newest, but how would I display the comments newest to oldest?

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 9/2/2009 1:17:14 AM
   
RE:Message Board comment counting
Hello,

You can find solution in following FAQ article: http://devnet.kentico.com/FAQs.aspx#FAQ189

I believe it will work as well :-)

Best Regards
Ondrej Vasil

User avatar
Member
Member
dantahoua-gmail - 2/6/2012 3:08:49 PM
   
RE:Message Board comment counting
Hello!
How can I count the number of message also but in Kentico 5.5 ? I tried this method but I always ended up with The name 'ltlRepeaterCount' does not exist in the current context... Seems that it can't find this object...

User avatar
Member
Member
kentico_michal - 2/7/2012 3:48:34 AM
   
RE:Message Board comment counting
Hello,

The ltlRepeaterCount is ID of the asp:Label control that you need to add to the HTML code of the Message board control (~\CMSModules\MessageBoards\Controls\MessageBoard.ascx) as it was mentioned in one of the previous posts.

Best regards,
Michal Legen

User avatar
Member
Member
dantahoua-gmail - 2/7/2012 3:00:04 PM
   
RE:Message Board comment counting
Thanks! I was tired, I tried to put this line of code in the transformation... :/ Now it works great!

User avatar
Certified Developer v6
Certified Developer v6
szarouski - 3/4/2012 10:05:06 PM
   
RE:Message Board comment counting
For anyone who will look for same question but for Kentico 6 - you can use following macro:
{%CurrentDocument.MessageBoards.MessageBoard.Children.BoardMessages.Count%}

User avatar
Certified Developer v6
Certified Developer v6
szarouski - 3/4/2012 10:17:37 PM
   
RE:Message Board comment counting
And if you want to use this macro in transformation you can use <%# CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros("some_macro") %>

User avatar
Member
Member
dantahoua-gmail - 5/13/2013 10:56:12 AM
   
RE:Message Board comment counting
Hello.
How could I use such a macro or something near it in my "ascx" file? I have
<div class="BlogCommentsTitle">
<%= ResHelper.GetString("blogs.header.comments") %> (<asp:Label ID="ltlRepeaterCount" runat="server" />)
</div>

with

void rptBoardMessages_DataBinding(object sender, EventArgs e)
{
if (!CMS.GlobalHelper.DataHelper.DataSourceIsEmpty(rptBoardMessages.DataSource))
{
System.Data.DataSet dv = rptBoardMessages.DataSource as System.Data.DataSet;
if (dv != null)
{
ltlRepeaterCount.Text = dv.Tables[0].Rows.Count.ToString();
}
}
}

but the ltlRepeaterCount do not work anymnore with Kentico 7... I'm not an expert... How could I replace that. I want to use it in the ASCX file because I have to put it on other places...
Thanks

User avatar
Member
Member
dantahoua-gmail - 5/13/2013 1:51:17 PM
   
RE:Message Board comment counting
I tried to put this code in the "Before content", all other Macro work but not this one. I have no errors, just nothing appears, like if the count is always 0... I'm with Kentico 7.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/14/2013 7:50:19 AM
   
RE:Message Board comment counting
dantahoua-gmail wrote: I tried to put this code in the "Before content", all other Macro work but not this one. I have no errors, just nothing appears, like if the count is always 0... I'm with Kentico 7.

In version 7 I believe you can use this in a repeater
<%# DataRowView.DataView.Count %>