一个比较好看的网页翻页效果_.Net教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:使用存储过程实现用户登录(含代码)
程序代码: public SqlDataReader GetUserLoginByProc(string sUserName,string sPassword) { ///创建链接 SqlConnection myConnection = new SqlConnection( ConfigurationManager.ConnectionStrings[数据库连接字符].ConnectionString); ///创建Command S

显示效果:1 2 3 4 5>> ,点击了4后又显示 ,4 5 6 7 8>>并转到第4页 ,如果总共有10页,  显示到6 7 8 9 10>>就不再显示了。

.aspx

<tr> <td align="center"><div class="tbl">
            【当前页:<asp:Label ID="lblcurpg" runat="server"></asp:Label> |  总记录数:<asp:Label ID="lblRecord" runat="server"></asp:Label>】 
        <%=strpg %>
    </div></td>
        </tr>

.cs

protected string strpg = string.Empty;
       
protected string strUrl = "aa.aspx";
       
protected int PgSize = 15;
       
protected string wherestr = string.Empty;
       
protected void Page_Load(object sender, EventArgs e)
        {
           
if (!Page.IsPostBack)
            {
               
int curpg = GetIdx();
               
if (Request.QueryString["val"] != null)
                {
                    wherestr
= Request.QueryString["val"].ToString();
                   
string strVal = "where NewsTitle like '%" + wherestr + "%' ";
                    Prepg(curpg, strVal);
                }
               
else
                {
                    Prepg(curpg, wherestr);
                }

                 }
        }

       
#region 加载页面
       
protected void Prepg(int Idx, string strWhere)
        {
            .....
//获取一个dataset
            int RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0].ItemArray[0].ToString());
            strpg
= Getpgstr(RecordCount, PgSize, Idx, strUrl);
            lblcurpg.Text
= Idx.ToString();
            lblRecord.Text
= RecordCount.ToString();
        }
       
#endregion

       
#region 获取分页控件
       
protected string Getpgstr(int total, int per, int page, string query_string)
        {
           
return pagination(total, per, page, query_string);
        }
       
#endregion

       
protected void btnSearch_Click(object sender, EventArgs e)
        {
            Response.Redirect(strUrl
+ "?val=" + txtNew.Text);
        }

       
#region 获取当前页
       
protected int GetIdx()
        {
           
int curpg;
           
if (Request.QueryString["page"] == null)
            {
                curpg
= 1;
            }
           
else
            {
                curpg
= Convert.ToInt32(Request.QueryString["page"].ToString());
            }
           
return curpg;
        }
       
#endregion 
public static string pagination(int total, int per, int page, string query_string)
        {
           
//page表是当前页
           
//per表示每页显示记录数
            int allpage = 0;
           
int next = 0;
           
int pre = 0;
           
int startcount = 0;
           
int endcount = 0;
           
string pagestr = "";
           
if (page < 1) { page = 1; }
           
//计算总页数
            if (per != 0)
            {
                allpage
= (total / per);
                allpage
= ((total % per) != 0 ? allpage + 1 : allpage);
                allpage
= (allpage == 0 ? 1 : allpage);
            }
            next
= page + 1;
            pre
= page - 1;
            startcount
= (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号
           
//中间页终止序号
            endcount = page < 5 ? 10 : page + 5;
           
if (startcount < 1) { startcount = 1; } //为了避免输出的时候产生负数,设置如果小于1就从序号1开始
            if (allpage < endcount) { endcount = allpage; }//页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内
            pagestr = "" + allpage + "页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

                pagestr
+= page > 1 ? "<a href=\"" + query_string + "?page=1\">首页</a>&nbsp;&nbsp;<a href=\"" + query_string + "?page=" + pre + "\">上一页</a>" : "<B>首页 上一页</B>";
               
//中间页处理,这个增加时间复杂度,减小空间复杂度
                for (int i = startcount; i <= endcount; i++)
                {
                    pagestr
+= page == i ? "&nbsp;&nbsp;<B>" + i + "<B>" : "&nbsp;&nbsp;<a href=\"" + query_string + "?page=" + i + "\">" + i + "</a>";
                }
                pagestr
+= page != allpage ? "&nbsp;&nbsp;<a href=\"" + query_string + "?page=" + next + "\">下一页</a>&nbsp;&nbsp;<a href=\"" + query_string + "?page=" + allpage + "\">末页</a>" : " 下一页 末页";

           
return pagestr;
        }
        


来源:csdn

分享:aspx页面弹出窗口代码大全
//关闭,父窗口弹出对话框,子窗口直接关闭 this.Response.Write(scriptlanguage=javascriptwindow.close();/script); //关闭,父窗口和子窗口都不弹出对话框,直接关闭 this.Response.Write(script); this.Response.Write({top.opener=null;top.close();}

来源:模板无忧//所属分类:.Net教程/更新时间:2012-06-18
相关.Net教程