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