网站首页 > 网络编程教程 > ASP.NET教程 > DATAGRID分页,增加首页、最后一页(源码)

DATAGRID分页,增加首页、最后一页(源码)

  • 作者:互联网
  • 时间:2009-07-01 16:27:08

1        private void PageCut_Click(Object sender,Sy***m.EventArgs ; e)
  2        {
  3            //取页码跳转标志(上一页,下一页)
  4            String commangArg = ((LinkButton)sender).CommandArgument ;
  5            switch(commangArg)
  6            {
  7                    //第一页
  8                case "First":
  9                {
 10                    DG***NE_CONTENT.CurrentPageIndex = 0;
 11                    break;
 12                }
 13                    //上一页
 14                case "Prev":
 15                {
 16                    DG***NE_CONTENT.CurrentPageIndex = (int)Math.Max(0,DG***NE_CONTENT.CurrentPageIndex - 1);
 17                    break;
 18                }
 19                    //下一页
 20                case "Next":
 21                {
 22                    DG***NE_CONTENT.CurrentPageIndex = (int)Math.Min(DG***NE_CONTENT.PageCount-1,DG***NE_CONTENT.CurrentPageIndex +1);
 23                    break;
 24                }
 25                    //最后一页
 26                case "Last":
 27                {
 28                    DG***NE_CONTENT.CurrentPageIndex  = DG***NE_CONTENT.PageCount -1;
 29                    break;
 30                }
 31                default:{break;}
 32            }
 33           
 34            th***Binder(th***TXT_SEARCH_NAME.Text.Trim().ToUpper(),th***TXT_SEARCH_CD.Text.Trim().ToUpper());       
 35            //控制页面导向按钮的可见性
 36      IsFirstLastPage();
 37        }
 38        /**////


 39        /// 控制页面导向按钮的可见性
 40        ///

 41        private void IsFirstLastPage()
 42        {
 43            if(DG***NE_CONTENT.PageCount > 0)
 44            {
 45                Pa***irst.Visible = true;
 46                Pa***ast.Visible = true;
 47                Pa***ext.Visible = true;
 48                Pa***rev.Visible = true;
 49
 50                if(DG***NE_CONTENT.PageCount != 1)
 51                {
 52                    if(DG***NE_CONTENT.CurrentPageIndex == 0)
 53                    {
 54                        Pa***rev.Enabled = false;
 55                    }
 56                    else
 57                    {
 58                        Pa***rev.Enabled = true;
 59                    }
 60                    if(DG***NE_CONTENT.CurrentPageIndex == DG***NE_CONTENT.PageCount -1)
 61                    {
 62                        Pa***ext.Enabled = false;
 63                    }
 64                    else
 65                    {
 66                        Pa***ext.Enabled = true;
 67                    }
 68                }
 69                else
 70                {
 71                    Pa***rev.Enabled = false;
 72                    Pa***ext.Enabled = false;
 73                }
 74            }
 75            else
 76            {
 77                Pa***irst.Visible = false;
 78                Pa***ast.Visible = false;
 79                Pa***ext.Visible = false;
 80                Pa***rev.Visible = false;
 81               
 82            }
 83        }
 84        private void Binder(string zone,string city)
 85        {
 86            bl = new ZoneConten();
 87            DataTable dt = new DataTable();
 88            if(zone==""&&city=="")
 89            {
 90                dt= bl***neRev("ZONE_INFO");
 91            }
 92            else
 93            {
 94                dt = bl***neSea(zone,city);
 95            }
 96            th***DG_ZONE_CONTENT.DataSource = dt;
 97            th***DG_ZONE_CONTENT.DataBind();
 98            if(dt!=null)
 99            {
100                if(dt***ws.Count>0)
101                {
102                    int nTotalCode = dt***ws.Count;
103                    //int nTotalPage = nTotalCode/10;
104                    //                if(nTotalCode%10>0)
105                    //                {nTotalPage=nTotalPage+1;}
106                    //                int a = 0;
107                    //***s.LBL_TOTAL.Text=nTotalPage.ToString();
108                    th***LBL_TOTAL.Text = nT***lCode.ToString();
109                    int nNow = this.DG***NE_CONTENT.CurrentPageIndex+1;
110                    th***LBL_NOW.Text=nNow.ToString();
111                }
112            }
113            else
114            {
115                th***LBL_TOTAL.Text = "0";
116                th***LBL_NOW.Text="1";
117            }
118            th***IsFirstLastPage();
119        }
120

                                                                                                                            AllowPaging="True" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White"
                                                                CellPadding="4">
                                                               
                                                               
                                                               
                                                               
                                                               
                                                                   
                                                                       
                                                                       
                                                                            <%#***aBinder.Eval(Container,"Da***tem.ZONE_CD") %>
                                                                           
                                                                           

                                                                       

                                                                   

                                                                   
                                                                       
                                                                       
                                                                            <%# Da***inder.Eval(Container,"Da***tem.AERA_NAME")%>
                                                                           
                                                                           

                                                                       

                                                                   

                                                                   
                                                                       
                                                                       
                                                                            <%# Da***inder.Eval(Container,"Da***tem.CITY")%>
                                                                           
                                                                           

                                                                       

                                                                   

                                                                   
                                                                       
                                                                   

                                                                   
                                                                       
                                                                   

                                                               

                                                               
                                                           

                                                       
                                                   
                                                   
                                                       
                                                             
                                                             
                                                             
                                                             
                                                            共Label 条记录,当前第
                                                            Label 页
                                                       
                                                   
http://www.cnblogs.com/semye/archive/2007