qq_31567651
A2103239473
采纳率100%
2018-11-22 23:23 阅读 600

悬赏:c#网站程序文章列表分页(上一页+下拉框跳转+下一页)

300

大神们,一网站程序,想改下文章列表分页显示!
我网站原来的显示样式是这样的:

图片说明

改成下面2图中任意一图都可以!

图片说明

图片说明

问题解决.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    showbo GoCityPass新加坡曼谷通票 2018-11-23 01:58

    有用记得采纳~~:)

    
        public void PageWrite(string contentCode)
        {
            if (this.Pconut >= 2)
            {
    
                string str = Regex.Replace(Regex.Replace(Regex.Replace(HttpContext.Current.Request.Url.ToString(), "&" + this.PageName + "=([0-9]*)", "", RegexOptions.IgnoreCase), "&" + this.PageName + "=([0-9]*)", "", RegexOptions.IgnoreCase), @"\?" + this.PageName + "=([0-9]*)", "?", RegexOptions.IgnoreCase).Replace("&", "&").Replace("&", "&");
    
                ////////////////////////////////////////////////下拉框
                string concatChr = str.Contains("?") ? "&" : "?";
                string select = "<select onchange='location=this.value'>";
                for (int i = 1; i <= this.Pconut; i++)
                {
                    select += "<option value='" + string.Concat(new object[] { "<a href=\"", str, concatChr, this.PageName, "=", i, "\">[下页]</a>" }) + "'>第" + i + "页</option>";
                }
                select += "</select>";
                ////////////////////////////////////////////////
                ///给你个建议,下面这个Contains完全没必要了,你就只是改个url连接字符串时&amp;或者&而已,我上面的代码已经有了,自己整合下下面的代码
                if (str.Contains("?"))
                {
                    if (this.Nowpage < this.Pconut)
                    {
                        HttpContext.Current.Response.Write(string.Concat(new object[] { "<a href=\"", str, "&amp;", this.PageName, "=", this.Nowpage + 1, "\">[下页]</a>" }));
                    }
    
                    HttpContext.Current.Response.Write(select);////////////////////////输出下拉框
                    if (this.Nowpage > 1)
                    {
                        HttpContext.Current.Response.Write(string.Concat(new object[] { "<a href=\"", str, "&amp;", this.PageName, "=", this.Nowpage - 1, "\">[上页]</a>" }));
                    }
                }
                else
                {
                    if (this.Nowpage < this.Pconut)
                    {
                        HttpContext.Current.Response.Write(string.Concat(new object[] { "<a href=\"", str, "?", this.PageName, "=", this.Nowpage + 1, "\">[下页]</a>" }));
                    }
                    HttpContext.Current.Response.Write(select);////////////////////////输出下拉框
                    if (this.Nowpage > 1)
                    {
                        HttpContext.Current.Response.Write(string.Concat(new object[] { "<a href=\"", str, "?", this.PageName, "=", this.Nowpage - 1, "\">[上页]</a>" }));
                    }
                }
                if ((this.Nowpage < this.Pconut) || (this.Nowpage > 1))
                {
                    HttpContext.Current.Response.Write("<br />");
                }
                HttpContext.Current.Response.Write(string.Concat(new object[] { "", contentCode, ",当前", this.Nowpage, "/", this.Pconut, "页<br/>" }));
                if (this.Pconut > 3)
                {
                    switch (MyTo.Toint(HttpContext.Current.Request.QueryString["v"]))
                    {
                        case 1:
                        case 2:
                            {
                                string str2 = HttpContext.Current.Request.QueryString.ToString();
                                if (!string.IsNullOrEmpty(str2))
                                {
                                    str2 = Regex.Replace(Regex.Replace(Regex.Replace(str2, "&amp;" + this.PageName + "=([0-9]*)", "", RegexOptions.IgnoreCase), "&" + this.PageName + "=([0-9]*)", "", RegexOptions.IgnoreCase), @"\?" + this.PageName + "=([0-9]*)", "?", RegexOptions.IgnoreCase).Replace("&amp;", "&");
                                }
                                HttpContext.Current.Response.Write("\r\n<form method=\"get\" name=\"form1\" action=\"" + HttpContext.Current.Request.ServerVariables["URL"] + "\">\r\n");
                                HttpContext.Current.Response.Write(string.Concat(new object[] { "<input name=\"", this.PageName, "\" format=\"*N\" emptyok=\"true\" maxlength=\"9\" size=\"3\" value=\"", this.Nowpage + 1, "\"/>\r\n" }));
                                if (!string.IsNullOrEmpty(str2))
                                {
                                    foreach (string str6 in str2.Split(new char[] { '&' }))
                                    {
                                        if (!string.IsNullOrEmpty(str6))
                                        {
                                            string str3 = MyTo.StringCut(str6, "", "=", 0);
                                            string str4 = MyTo.StringCut(str6, "=", "", 0);
                                            if (str3 != this.PageName)
                                            {
                                                HttpContext.Current.Response.Write("<input name=\"" + str3 + "\" type=\"hidden\" id=\"" + str3 + "\" value=\"" + str4 + "\"/>\r\n");
                                            }
                                        }
                                    }
                                }
                                HttpContext.Current.Response.Write("<input type=\"submit\" class=submit value=\"跳到此页\"/>\r\n");
                                HttpContext.Current.Response.Write("</form><br/>\r\n");
                                return;
                            }
                    }
                    string str5 = DateTime.Now.ToString("yyMdHmmss");
                    HttpContext.Current.Response.Write(string.Concat(new object[] { "<input name=\"page", str5, "\" format=\"*N\" emptyok=\"true\" maxlength=\"9\" size=\"3\" value=\"", this.Nowpage + 1, "\"/>" }));
                    HttpContext.Current.Response.Write("<anchor title=\"Go\">[跳到此页]");
                    HttpContext.Current.Response.Write("<go href=\"" + str + "\" sendreferer=\"true\" method=\"get\" accept-charset=\"utf-8\">");
                    HttpContext.Current.Response.Write("<postfield name=\"" + this.PageName + "\" value=\"$(page" + str5 + ")\"/>");
                    HttpContext.Current.Response.Write("</go></anchor><br/>");
                }
            }
        }
    
        public void PageWrite(string contentCode, string _Page_Url)
        {
            if (this.Pconut >= 2)
            {
                _Page_Url = Regex.Replace(_Page_Url, "&amp;" + this.PageName + "=([0-9]*)", "", RegexOptions.IgnoreCase);
                _Page_Url = Regex.Replace(_Page_Url, "&" + this.PageName + "=([0-9]*)", "", RegexOptions.IgnoreCase);
                _Page_Url = Regex.Replace(_Page_Url, @"\?" + this.PageName + "=([0-9]*)", "?", RegexOptions.IgnoreCase);
                _Page_Url = _Page_Url.Replace("&amp;", "&");
                _Page_Url = _Page_Url.Replace("&", "&amp;");
    
                ////////////////////////////////////////////////下拉框
                string concatChr = _Page_Url.Contains("?") ? "&amp;" : "?";
                string select = "<select onchange='location=this.value'>";
                for (int i = 1; i <= this.Pconut; i++)
                {
                    select += "<option value='" + string.Concat(new object[] { "<a href=\"", _Page_Url, concatChr, this.PageName, "=", i, "\">[下页]</a>" }) + "'>第" + i + "页</option>";
                }
                select += "</select>";
                ////////////////////////////////////////////////
                if (_Page_Url.Contains("?"))
                {
                    if (this.Nowpage < this.Pconut)
                    {
                        HttpContext.Current.Response.Write(string.Concat(new object[] { "<a href=\"", _Page_Url, "&amp;", this.PageName, "=", this.Nowpage + 1, "\">[下页]</a>" }));
                    }
                    HttpContext.Current.Response.Write(select);////////////////////////输出下拉框
                    if (this.Nowpage > 1)
                    {
                        HttpContext.Current.Response.Write(string.Concat(new object[] { "<a href=\"", _Page_Url, "&amp;", this.PageName, "=", this.Nowpage - 1, "\">[上页]</a>" }));
                    }
                }
                else
                {
                    if (this.Nowpage < this.Pconut)
                    {
                        HttpContext.Current.Response.Write(string.Concat(new object[] { "<a href=\"", _Page_Url, "?", this.PageName, "=", this.Nowpage + 1, "\">[下页]</a>" }));
                    }
                    HttpContext.Current.Response.Write(select);////////////////////////输出下拉框
                    if (this.Nowpage > 1)
                    {
                        HttpContext.Current.Response.Write(string.Concat(new object[] { "<a href=\"", _Page_Url, "?", this.PageName, "=", this.Nowpage - 1, "\">[上页]</a>" }));
                    }
                }
                if ((this.Nowpage < this.Pconut) || (this.Nowpage > 1))
                {
                    HttpContext.Current.Response.Write("<br />");
                }
                HttpContext.Current.Response.Write(string.Concat(new object[] { "", contentCode, ",当前", this.Nowpage, "/", this.Pconut, "页<br/>" }));
                if (this.Pconut > 3)
                {
                    switch (MyTo.Toint(HttpContext.Current.Request.QueryString["v"]))
                    {
                        case 1:
                        case 2:
                            {
                                string str = HttpContext.Current.Request.QueryString.ToString();
                                if (!string.IsNullOrEmpty(str))
                                {
                                    str = Regex.Replace(Regex.Replace(Regex.Replace(str, "&amp;" + this.PageName + "=([0-9]*)", "", RegexOptions.IgnoreCase), "&" + this.PageName + "=([0-9]*)", "", RegexOptions.IgnoreCase), @"\?" + this.PageName + "=([0-9]*)", "?", RegexOptions.IgnoreCase).Replace("&amp;", "&");
                                }
                                HttpContext.Current.Response.Write("\r\n<form method=\"get\" name=\"form1\" action=\"" + HttpContext.Current.Request.ServerVariables["URL"] + "\">\r\n");
                                HttpContext.Current.Response.Write(string.Concat(new object[] { "<input name=\"", this.PageName, "\" format=\"*N\" emptyok=\"true\" maxlength=\"9\" size=\"3\" value=\"", this.Nowpage + 1, "\"/>\r\n" }));
                                if (!string.IsNullOrEmpty(str))
                                {
                                    foreach (string str5 in str.Split(new char[] { '&' }))
                                    {
                                        if (!string.IsNullOrEmpty(str5))
                                        {
                                            string str2 = MyTo.StringCut(str5, "", "=", 0);
                                            string str3 = MyTo.StringCut(str5, "=", "", 0);
                                            if (str2 != this.PageName)
                                            {
                                                HttpContext.Current.Response.Write("<input name=\"" + str2 + "\" type=\"hidden\" id=\"" + str2 + "\" value=\"" + str3 + "\"/>\r\n");
                                            }
                                        }
                                    }
                                }
                                HttpContext.Current.Response.Write("<input type=\"submit\" class=submit value=\"跳到此页\"/>\r\n");
                                HttpContext.Current.Response.Write("</form><br/>\r\n");
                                return;
                            }
                    }
                    string str4 = DateTime.Now.ToString("yyMdHmmss");
                    HttpContext.Current.Response.Write(string.Concat(new object[] { "<input name=\"page", str4, "\" format=\"*N\" emptyok=\"true\" maxlength=\"9\" size=\"3\" value=\"", this.Nowpage + 1, "\"/>" }));
                    HttpContext.Current.Response.Write("<anchor title=\"Go\">[跳到此页]");
                    HttpContext.Current.Response.Write("<go href=\"" + _Page_Url + "\" sendreferer=\"true\" method=\"get\" accept-charset=\"utf-8\">");
                    HttpContext.Current.Response.Write("<postfield name=\"page\" value=\"$(page" + str4 + ")\"/>");
                    HttpContext.Current.Response.Write("</go></anchor><br/>");
                }
            }
        }
    
    
    点赞 4 评论 复制链接分享

相关推荐