Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 17th, 2007, 04:07 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default Forums Extensions III - PageLinks on BrowseThreads

If someone wants to add Page Threads Links to BrowseThreads Page do this:
(This script can redirect too to last page!
If you want to go to the second page of thread127 you use ...showthread.aspx?threadid=127&pg=2
If you want to go to the last page of thread127 you use ...showthread.aspx?threadid=127&pg=last

The result is:
http://img521.imageshack.us/img521/1...nkpagespm9.jpg
(1,..., last pages) I think that when a user browse threads he has two options:
- Never saw the thread and want to start from 1
- Already saw the thread and want to go to the last pages
  (So I think it's unnecessary put the middle pages)

Add this to the ConfigSettings:
Code:
....
        <ConfigurationProperty("postsPageSize", DefaultValue:="10")> _
        Public Property PostsPageSize() As Integer
            Get
                Return CInt(Me("postsPageSize"))
            End Get
            Set(ByVal value As Integer)
                Me("postsPageSize") = value
            End Set
        End Property
....
On BrowseThreads.aspx I have this:
//Notice that I have My AddedBy Label in the Title Cell but this a metter of taste...
Code:
....
<asp:TemplateField HeaderText="Thread Title">
            <ItemTemplate>
               <asp:HyperLink ID="lnkTitle" Font-Bold="true" runat="server" Text='<%# Eval("Title") %>' 
                  NavigateUrl='<%# "ShowThread.aspx?ID=" & Eval("ID") %>' /><br />
               by <asp:Label ID="lblAddedBy" runat="server" Text='<%# Eval("AddedBy") & " " & setPager(Eval("ReplyCount"), Eval("ID")) %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="Left" />
         </asp:TemplateField>
...
On BrowseThreads Code-behind:
Code:
...
Public Function SetPager(ByVal totReplies As Integer, ByVal topicId As String) As String

            totReplies += 1 'Because post.RepliesCount don't count with the firstPost!
            Dim postsPerPag As Integer = Globals.Settings.Forums.PostsPageSize
            Dim strReturn As String = ""
            Dim numToDisplay As Integer = 4  '//This editable... You can put how many links you want!
            Dim pageCount As Integer = CInt(Math.Ceiling((System.Convert.ToDouble(totReplies) / postsPerPag)))
            If pageCount > 1 Then
                strReturn += "  "
                If (pageCount > numToDisplay) Then
                    strReturn += makeLink("1", "ShowThread.aspx?ID=" & topicId.ToString)
                    strReturn += " ... "
                    Dim bFirst As Boolean = True
                    For i As Integer = pageCount - (numToDisplay - 1) To pageCount - 1
                        Dim ipost As Integer = i + 1
                        If bFirst Then
                            bFirst = False
                        Else : strReturn += ", "
                        End If
                        strReturn += makeLink(ipost.ToString(), String.Format("ShowThread.aspx?ID={0}&pg={1}", topicId.ToString, ipost))
                    Next
                Else
                    Dim bFirst As Boolean = True
                    For i As Integer = 0 To pageCount - 1
                        Dim ipost As Integer = i + 1
                        If bFirst Then
                            bFirst = False
                        Else : strReturn += ", "
                        End If
                        strReturn += makeLink(ipost.ToString(), String.Format("ShowThread.aspx?ID={0}&pg={1}", topicId.ToString, ipost))
                    Next
                End If
                Return strReturn

            End If
        End Function

        Private Function makeLink(ByVal Text As String, ByVal Link As String) As String
            Return String.Format("<a href=""{0}"">{1}</a>", Link, Text)
        End Function
...
On ShowThread Code-behind:
Code:
        Dim pageGrid As Integer = 1 
...
        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            gvwPosts.PageSize = Globals.Settings.Forums.PostsPageSize
        End Sub
...

'// Page load...
...

    If Not Me.IsPostBack Then
           ...
                If Not String.IsNullOrEmpty(Me.Request.QueryString("pg")) Then
                    If Not Me.Request.QueryString("pg") = "last" Then
                        pageGrid = Integer.Parse(Me.Request.QueryString("pg"))
                    Else : pageGrid = CInt(Math.Ceiling(((System.Convert.ToDouble(post.ReplyCount) + 1) / Globals.Settings.Forums.PostsPageSize)))
                    End If
                End If
                gvwPosts.PageIndex = pageGrid - 1 '//Because gridView pages start from 0!
    End If
-- END ---

The SetPager Function give some work to do! But here you go! I hope this helps to improve your forums!

Max
 
Old October 17th, 2007, 04:36 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

max,

you must have been reading my mind tonite ;)

thanks for that

jimi

http://www.originaltalent.com
 
Old October 17th, 2007, 04:41 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

max - also, create a description of this and copy a link into the:

http://p2p.wrox.com/topic.asp?TOPIC_ID=65847

thread, so that it remains sticky. this such a nice addition.

jimi

http://www.originaltalent.com
 
Old October 17th, 2007, 06:32 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok,

Jimi, if you, or any other, try to implement this under C# Version, wrote here the same script(in C#) for it.

Like I said, the setPager function was the hard stuff... But I think the translation is simple!

Sometimes I use this tool to translate C# to VB: HERE
Then I "Paste" the result to my VS2005 and try to change some errors that this tool couldn't handle...
(This is just an idea)


 
Old October 18th, 2007, 03:06 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Max,

used the convertor at: http://labs.developerfusion.co.uk/co...to-csharp.aspx

and got these translations for c#:

Add this to the ConfigSettings:

[ConfigurationProperty("postsPageSize", DefaultValue = "10")]
public int PostsPageSize {
    get { return (int)this("postsPageSize"); }
    set { this("postsPageSize") = value; }
}

i also added this in addition (for the setPager function):

        [ConfigurationProperty("postsLinkSize", DefaultValue = "4")]
        public int PostsLinkSize
        {
            get { return (int)base["postsLinkSize"]; }
            set { base["postsLinkSize"] = value; }
        }

On BrowseThreads.aspx I have this:
//Notice that I have My AddedBy Label in the Title Cell but this a metter of taste...

<asp:TemplateField HeaderText="Thread Title">
            <ItemTemplate>
             <asp:HyperLink ID="lnkTitle" Font-Bold="true" runat="server" Text='<%# Eval("Title") %>'
                 NavigateUrl='<%# "ShowThread.aspx?ID=" & Eval("ID") %>' /><br />
             by <asp:Label ID="lblAddedBy" runat="server" Text='<%# Eval("AddedBy") + " " + setPager(Convert.ToInt32(Eval("ReplyCount")), Convert.ToString(Eval("ID"))) %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle HorizontalAlign="Left" />
         </asp:TemplateField>


On BrowseThreads Code-behind:

        public string setPager(int totReplies, string topicId)
        {
            totReplies += 1; //Because post.RepliesCount don't count with the firstPost!
            int postsPerPage = Globals.Settings.Forums.PostsPageSize;
            string strReturn = "";
            int numToDisplay = Globals.Settings.Forums.PostsLinkSize; //This editable... You can put how many links you want!
            int pageCount = (int)Math.Ceiling((System.Convert.ToDouble(totRepl ies) / postsPerPage));
            if (pageCount > 1)
            {
                strReturn += " ";
                if ((pageCount > numToDisplay))
                {
                    string strLink = "ShowThread.aspx?ID=" + topicId.ToString();
                    strReturn += makeLink("1", strLink);
                    strReturn += " ... ";
                    bool bFirst = true;
                    for (int i = pageCount - (numToDisplay - 1); i <= pageCount - 1; i++)
                    {
                        int ipost = i + 1;
                        strReturn += (bFirst == true ? "" : ", ");
                        bFirst = false;
                        strReturn += makeLink(ipost.ToString(), string.Format("ShowThread.aspx?ID={0}&pg={1}", topicId, ipost.ToString()));
                    }
                }
                else
                {
                    bool bFirst = true;
                    for (int i = 0; i <= pageCount - 1; i++)
                    {
                        int ipost = i + 1;
                        strReturn += (bFirst == true ? "" : ", ");
                        bFirst = false;
                        strReturn += makeLink(ipost.ToString(), string.Format("ShowThread.aspx?ID={0}&pg={1}", topicId, ipost.ToString()));
                    }
                }
            }
            return strReturn;
        }

        private string makeLink(string Text, string Link)
        {
            return string.Format("<a href=\"{0}\">{1}</a>", Link, Text);
        }

On ShowThread Code-behind:


int pageGrid = 1;

protected void Page_Init(object sender, System.EventArgs e)
{
    gvwPosts.PageSize = Globals.Settings.Forums.PostsPageSize;
}


// Page load...

        if (!this.IsPostBack)
        {
        // other stuff in happens between the
        // ispostback declaration and our post test
        // but not shown here for the sake of brevity
                if (post != null)
                {
                    if (!string.IsNullOrEmpty(this.Request.QueryString["pg"]))
                    {
                        if (!(this.Request.QueryString["pg"] == "last"))
                        {
                            pageGrid = int.Parse(this.Request.QueryString["pg"]);
                        }
                        else
                        {
                            pageGrid = (int)Math.Ceiling(((System.Convert.ToDouble(post.R eplyCount) + 1) / Globals.Settings.Forums.PostsPageSize));
                        }
                    }
                    gvwPosts.PageIndex = pageGrid - 1;
                    ////Because gridView pages start from 0!
                }
        }

[edit] the 1st attempt that i made on this had a few errors in it (i.e. i blindly ran it against the convertor). i've now tested it implemented in code and made the neccesary corrections and it all works now in c#.

jimi

http://www.originaltalent.com
 
Old October 18th, 2007, 05:01 AM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Jimi!
When you try it confirm if it works...

 
Old October 23rd, 2007, 10:25 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

max -see above. i've corrected the c# conversion by hand and it works perfectly.

great job, thanks ;)

jimi

http://www.originaltalent.com
 
Old October 23rd, 2007, 10:41 AM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm glad you made the translation!

Thanks!

 
Old December 10th, 2007, 05:08 PM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 131
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kherrerab Send a message via Yahoo to kherrerab
Default

something like this sould be done when you click the link in the forum rss.

 
Old December 11th, 2007, 07:08 PM
Authorized User
 
Join Date: Aug 2007
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank You for saving our time on this subject! Works fine!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Some Extensions plb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 July 29th, 2008 11:57 AM
Forums Extensions II - New/Old Posts Maxxim BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 September 21st, 2007 03:50 AM
PHP Extensions Dnigma Pro PHP 0 June 22nd, 2006 12:41 AM
dbas III kolani VB Databases Basics 0 August 10th, 2005 06:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.