C# 分页程序 加一个跳转页
如跳转()页 go 谁有现成的代码分享一下。

解决方案 »

  1.   

     private void button6_Click(object sender, EventArgs e)
            {
                if (this.textBox2.Text != "" && textBox2.Text.ToString().Length == Encoding.Default.GetByteCount(textBox2.Text.ToString()))
                {
                    if (int.Parse(this.textBox2.Text) > pagecount)
                    {
                        MessageBox.Show("当前查询结果没那么多页来跳转.");
                    }
                    else
                    {
                        kk1(int.Parse(this.textBox2.Text));
                    }
                }        }
      

  2.   

    <asp:GridView>    
     
     
     
     
    <pagertemplate> 
                            <table width="100%"> 
                              <tr> 
                                <td style="text-align:right"> 
                                第 <asp:Label id="lblPageIndex" runat="server" text=' <%# ((GridView)Container.Parent.Parent).PageIndex + 1  %>' />页 
                                    共/ <asp:Label id="lblPageCount" runat="server" text=' <%# ((GridView)Container.Parent.Parent).PageCount  %>' />页 
                                    <asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" /> 
                                  <asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" /> 
                                <asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />                          
                                <asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />                                            
                                <asp:textbox id="txtNewPageIndex" runat="server" width="20px" text=' <%# ((GridView)Container.Parent.Parent).PageIndex + 1  %>' /> 
                                <asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /> <!-- here set the CommandArgument of the Go Button to '-1' as the flag --> 
                                </td> 
                              </tr> 
                            </table> 
                        </pagertemplate>         </asp:GridView> 
    aa.aspx.cs 文件 
        protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e) 
        { 
            GridView2.PageIndex = e.NewPageIndex; 
            GridView2.DataBind(); 
        }
      

  3.   

    public void kk1(int ss)
            {
                
                page  = ss;
                getpagecount();
                if (sqlvalue != "")
                {
                    keysql = sqlvalue;            }
                if (page <= 1)
                {
                    page = 1;
                    sqlpage = "select top " + pagesize + " * from 表1";
                    this.button2.Enabled = false;
                    if (pagecount > page)
                    {
                        this.button3.Enabled = true;
                    }
                }
                else if (page >= pagecount)
                {
                    sqlpage = "select top " + pagesize + " * from 表1 where 序号 > (select max(序号) from (select top " + (page - 1) * pagesize + " 序号 from 表1 where   order by 序号 asc) as temp)   order by 序号 asc";
                    if (pagecount > 1)
                    {
                        this.button2.Enabled = true;
                    }
                    this.button3.Enabled = false;
                }
                else
                {
                    sqlpage = "select top " + pagesize + " * from 表1 where 序号 > (select max(序号) from (select top " + (page - 1) * pagesize + " 序号 from 表1 where   order by 序号 asc) as temp)     order by 序号 asc";
                    this.button3.Enabled = true;
                    this.button2.Enabled = true;
                }            ds = ws.getdata1(sqlpage);
                dt = ds.Tables[0];
                this.dataGridView1.DataSource = dt;
                this.toolStripStatusLabel3.Text = "当前页记录数为" + dt.Rows.Count.ToString() + "行";
      

  4.   

     public void getpagecount()
            {
                if (sqlvalue != "")
                {
                    keysql = " where " + sqlvalue;            }
                DataSet dw = ws.getdata1("select 序号 from 表1");
                count = dw.Tables[0].Rows.Count;            if (count % pagesize == 0)
                {
                    pagecount = count / pagesize;
                }
                else
                {
                    pagecount = count / pagesize + 1;
                }
                this.toolStripStatusLabel2.Text = "每页显示记录数为40行,共 " + pagecount.ToString() + " 页,当前第 " + page.ToString() + " 页,";
            }
      

  5.   

    三楼的写法,为什么直接绑定数据源,就行,调用存储过程或自己写的sql就不行。
    ((TextBox)GridView1.BottomPagerRow.FindControl("txtGoPage")).Text)是空的
      

  6.   

    直接用存储过程分页+AspNetPager控件吧.
      

  7.   

    用aspnetpager控件更简单
     参考
      

  8.   

    3楼,怎么和我的回复一样,不过VS自动绑定的可以,自己写调的sql或存储过程就不行了。