Slick86_98
2009-05-15T10:49:51Z
Hey guys, I am trying to integrate the forum with my main page. I have a news Category that I want to show up with only the newest topics in that category. Then I also want to use <Yaf:activeDiscussions> on my main page as well. My forum is located in "/forum/" and when I click on a link, the page tries to postback to the calling page name in that folder instead of the forum default page in that folder. I was also wondering how to get the topics out of that specific category and show them on my main page? Any ideas?
Sponsor
Mek
  •  Mek
  • 100% (Exalted)
  • YAF Developer
2009-05-15T11:04:01Z
In the interests of time saving; I'm simply using the Active Discussions RSS Feed instead of using the control. But I'd be interested if someone else has got the above working.

UserPostedImage 

"It's a case of RTFM.. the only problem being we don't have a manual!"

When I post FP:Mek in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Ederon 🙂 )
Slick86_98
2009-05-15T13:03:47Z
I will try the rss idea. That would actually work for both of the things i am doing. Do you recommend that i use an xmldatareader or a 3rd party rss reader for asp.net? I am a pretty decent coder but i have never used rss before.
Slick86_98
2009-05-15T15:48:14Z
I tried it with XMlDataReader and i kinda works. Is it possible to make the rss feed show the contents of the first post in the topic?
SSDExecutor
2009-05-18T05:00:43Z
I didn't actually use that control, but I used some of the code behind it to create my own. I made a webcontrol using a datalist like this:

<asp:datalist id="dlForumPosts" runat="server">
            <alternatingitemstyle backcolor="Silver" />
            <itemtemplate>
                <div style="padding: 2px;">
                    <asp:hyperlink id="hlPost" runat="server" navigateurl='<%# "/forums/Default.aspx?g=posts&m=" & eval("LastMessageID") & "#" & eval("LastMessageID")%>'><%#Eval("Topic")%></asp:hyperlink>
                    <div style="margin-left: 10px;">
                        in <span style="font-weight: bold;">
                            <%#Eval("Forum")%></span> on
                        <%#MethodsUtility.ConvertDateToEnglish(eval("LastPosted"), True)%>
                        by
                        <%#Eval("LastUserName")%></div>
                </div>
            </itemtemplate>
        </asp:datalist>


and then added this to the Page Load method:

Dim dtActivePosts As DataTable = YAF.Classes.Data.DB.topic_latest(1, 10, Profile.YAF.UserID)
        dlForumPosts.DataSource = dtActivePosts
        dlForumPosts.DataBind()


You can see what it looks like on our front page at http://www.redstickrebellion.com/ . Hope that helps.
Slick86_98
2009-05-21T13:23:55Z
Thank you! That works awesome! Do you know if there is a way to get the initial contents of the Topic post as well? I wanted to do news separate with a title and information instead of the user having to click to view it.
SSDExecutor
2009-05-22T04:29:48Z
No problem Slick! If you're trying to get the text from the actual post, you need to take the LastMessageID value for each item and get it from the yaf_Message table of the YAF database. Something like this:

Add a label to the itemtempate of the datalist, like this:

       <asp:datalist id="dlForumPosts" runat="server">
            <alternatingitemstyle backcolor="Silver" />
            <itemtemplate>
                <div style="padding: 2px;">
                    <asp:hyperlink id="hlPost" runat="server" navigateurl='<%# "/forums/Default.aspx?g=posts&m=" & eval("LastMessageID") & "#" & eval("LastMessageID")%>'><%#Eval("Topic")%></asp:hyperlink>
                    <div style="margin-left: 10px;">
                        in <span style="font-weight: bold;">
                            <%#Eval("Forum")%></span> on
                        <%#MethodsUtility.ConvertDateToEnglish(eval("LastPosted"), True)%>
                        by
                        <%#Eval("LastUserName")%></div>
                </div>
                <asp:label id="lblPostContent" runat="server" />
            </itemtemplate>
        </asp:datalist>


Then add an event to the datalist's ItemDataBound event, like this:

    Protected Sub dlForumPosts_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlForumPosts.ItemDataBound
        Dim dtTopic As DataTable = YAF.Classes.Data.DB.message_list(e.Item.DataItem("LastMessageID"))
        DirectCast(e.Item.FindControl("lblPostContent"), Label).Text = dtTopic.Rows(0)("Message")
    End Sub


Now, this will read from the database once for each post that you show - so if you're doing a good number of them it may be worth it to pre-load the table straight from the YAF database and just filter each time you enter the ItemDataBound method - but this should give you a good place to start. Hope that helps.
Slick86_98
2009-06-09T11:04:23Z
Thanks! I had to approach it a bit differently because i am writing in C# and it would not let me do it the way you wrote it out. I ended up creating a new datatable on page load and added the message.

foreach (DataRow row in dtActivePosts.Rows)
        {
            if (!row["ForumID"].Equals(2))
            {
                row2 = newsExclude.NewRow();
                row2["LastMessageID"] = row["LastMessageID"];
                row2["Topic"] = row["Topic"];
                row2["Forum"] = row["Forum"];
                row2["LastUserName"] = row["LastUsername"];

                DataTable dtTopic = YAF.Classes.Data.DB.message_list(row["LastMessageID"]);
                DataRow row3 = dtTopic.Rows[0];
                row2["Message"] = row3["Message"].ToString();

                newsExclude.Rows.Add(row2);
            }
        }


Now each one is all set up. I implemented it on http://www.extremeautoslo.com/upgrade 

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved