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

2016-02-19 21:53 40 1 收藏

关注图老师设计创意栏目可以让大家能更好的了解电脑,知道有关于电脑的更多有趣教程,今天给大家分享DATAGRID分页增加首页、最后一页(源码)教程,希望对大家能有一点小小的帮助。

【 tulaoshi.com - Web开发 】

  1        private void PageCut_Click(Object sender,System.EventArgs  e)
    2        {
    3            //取页码跳转标志(上一页,下一页)
    4            String commangArg = ((LinkButton)sender).CommandArgument ;
    5            switch(commangArg)
    6            {
    7                    //第一页
    8                case "First":
    9                {
   10                    DG_ZONE_CONTENT.CurrentPageIndex = 0;
   11                    break;
   12                }
   13                    //上一页
   14                case "Prev":
   15                {
   16                    DG_ZONE_CONTENT.CurrentPageIndex = (int)Math.Max(0,DG_ZONE_CONTENT.CurrentPageIndex - 1);
   17                    break;
   18                }
   19                    //下一页
   20                case "Next":
   21                {
   22                    DG_ZONE_CONTENT.CurrentPageIndex = (int)Math.Min(DG_ZONE_CONTENT.PageCount-1,DG_ZONE_CONTENT.CurrentPageIndex +1);
   23                    break;
   24                }
   25                    //最后一页
   26                case "Last":
   27                {
   28                    DG_ZONE_CONTENT.CurrentPageIndex  = DG_ZONE_CONTENT.PageCount -1;
   29                    break;
   30                }
   31                default:{break;}
   32            }
   33           
   34            this.Binder(this.TXT_SEARCH_NAME.Text.Trim().ToUpper(),this.TXT_SEARCH_CD.Text.Trim().ToUpper());       
   35            //控制页面导向按钮的可见性
   36  IsFirstLastPage();
   37        }
   38        /**//// summary
   39        /// 控制页面导向按钮的可见性
   40        /// /summary
   41        private void IsFirstLastPage()
   42        {
   43            if(DG_ZONE_CONTENT.PageCount 0)
   44            {
   45                PageFirst.Visible = true;
   46                PageLast.Visible = true;
   47                PageNext.Visible = true;
   48                PagePrev.Visible = true;
   49
   50                if(DG_ZONE_CONTENT.PageCount != 1)
   51                {
   52                    if(DG_ZONE_CONTENT.CurrentPageIndex == 0)
   53                    {
   54                        PagePrev.Enabled = false;
   55                    }
   56                    else
   57                    {
   58                        PagePrev.Enabled = true;
   59                    }
   60                    if(DG_ZONE_CONTENT.CurrentPageIndex == DG_ZONE_CONTENT.PageCount -1)
   61                    {
   62                        PageNext.Enabled = false;
   63                    }
   64                    else
   65                    {
   66                        PageNext.Enabled = true;
   67                    }
   68                }
   69                else
   70                {
   71                    PagePrev.Enabled = false;
   72                    PageNext.Enabled = false;
   73                }
   74            }
   75            else
   76            {
   77                PageFirst.Visible = false;
   78                PageLast.Visible = false;
   79                PageNext.Visible = false;
   80                PagePrev.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.ZoneRev("ZONE_INFO");
   91            }
   92            else
   93            {
   94                dt = bl.zoneSea(zone,city);
   95            }
   96            this.DG_ZONE_CONTENT.DataSource = dt;
   97            this.DG_ZONE_CONTENT.DataBind();
   98            if(dt!=null)
   99            {
  100                if(dt.Rows.Count0)
  101                {
  102                    int nTotalCode = dt.Rows.Count;
  103                    //int nTotalPage = nTotalCode/10;
  104                    //                if(nTotalCode%100)
  105                    //                {nTotalPage=nTotalPage+1;}
  106                    //                int a = 0;
  107                    //this.LBL_TOTAL.Text=nTotalPage.ToString();
  108                    this.LBL_TOTAL.Text = nTotalCode.ToString();
  109                    int nNow = this.DG_ZONE_CONTENT.CurrentPageIndex+1;
  110                    this.LBL_NOW.Text=nNow.ToString();
  111                }
  112            }
  113            else
  114            {
  115                this.LBL_TOTAL.Text = "0";
  116                this.LBL_NOW.Text="1";
  117            }
  118            this.IsFirstLastPage();
  119        }
  120

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

                                                              asp:datagrid id="DG_ZONE_CONTENT" runat="server" Width="792px" GridLines="Horizontal" AutoGenerateColumns="False"
                                                                  AllowPaging="True" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White"
                                                                  CellPadding="4"
                                                                  SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"/SelectedItemStyle
                                                                  ItemStyle ForeColor="#330099" BackColor="White"/ItemStyle
                                                                  HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#99CCFF"/HeaderStyle
                                                                  FooterStyle ForeColor="#330099" BackColor="#FFFFCC"/FooterStyle
                                                                  Columns
                                                                      asp:TemplateColumn HeaderText="行区代码"
                                                                          HeaderStyle Width="60px"/HeaderStyle
                                                                          ItemTemplate
                                                                              %#DataBinder.Eval(Container,"DataItem.ZONE_CD") %
                                                                              asp:TextBox id=TXT_ZONE_CD_VIS runat="server" Width="58px" Height="20px" Visible="false" text='%#DataBinder.Eval(Container,"DataItem.ZONE_CD")%'
                                                                              /asp:TextBox
                                                                          /ItemTemplate
                                                                      /asp:TemplateColumn
                                                                      asp:TemplateColumn HeaderText="行区名"
                                                                          HeaderStyle Width="100px"/HeaderStyle
                                                                          ItemTemplate
                                                                              %# DataBinder.Eval(Container,"DataItem.AERA_NAME")%
                                                                              asp:TextBox id=TXT_ZONE_NAME_VIS runat="server" Width="164px" Visible="False" Text='%# DataBinder.Eval(Container,"DataItem.AERA_NAME")%'
                                                                              /asp:TextBox
                                                                          /ItemTemplate
                                                                      /asp:TemplateColumn
                                                                      asp:TemplateColumn HeaderText="城市代码"
                                                                          HeaderStyle Width="200px"/HeaderStyle
                                                                          ItemTemplate
                                                                              %# DataBinder.Eval(Container,"DataItem.CITY")%
                                                                              asp:TextBox id=TXT_ZONE_CITY_VIS runat="server" Width="135px" Visible="False" Text='%# DataBinder.Eval(Container,"DataItem.CITY")%'
                                                                              /asp:TextBox
                                                                          /ItemTemplate
                                                                      /asp:TemplateColumn
                                                                      asp:ButtonColumn Text="修改" CommandName="Select"
                                                                          HeaderStyle Width="100px"/HeaderStyle
                                                                      /asp:ButtonColumn
                                                                      asp:ButtonColumn Text="删除" CommandName="Delete"
                                                                          HeaderStyle Width="50px"/HeaderStyle
                                                                      /asp:ButtonColumn
                                                                  /Columns
                                                                  PagerStyle Visible="false" HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"/PagerStyle
                                                              /asp:datagrid
                                                          /td
                                                      /tr
                                                      tr
                                                          td
                                                              asp:linkbutton id="PageFirst" Runat="server" CssClass="Normal" Text="首页" CommandArgument="First"/asp:linkbutton 
                                                              asp:linkbutton id="PagePrev" Runat="server" CssClass="Normal" Text="上一页" CommandArgument="Prev"/asp:linkbutton 
                                                              asp:linkbutton id="PageNext" runat="server" CssClass="Normal" Text="下一页" CommandArgument="Next"/asp:linkbutton 
                                                              asp:linkbutton id="PageLast" Runat="server" CssClass="Normal" Text="最后一页" CommandArgument="Last"/asp:linkbutton 
                                                              共asp:label id="LBL_TOTAL" runat="server"Label/asp:label 条记录,当前第
                                                              asp:label id="LBL_NOW" runat="server"Label/asp:label 页
                                                          /td
                                                      /tr
  http://www.cnblogs.com/semye/archive/2007

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

来源:http://www.tulaoshi.com/n/20160219/1627345.html

延伸阅读
标签: Web开发
刚在ajacn发了个贴,关于为XMLHttpRequest提供一个对象池。或许能帮到你,转贴如下: 在网上看到了有些同志提到了为Ajax的XMLHttpRequest提供一个对象池,也读了他们给出的实现代码。感觉不是特别理想,于是模仿apache的commons中的ObjectPool的思路写了一个简单的JavaScript版。  望指教:  代码 function ObjectPool(poo...
标签: word
Word分栏时最后一页分为行数相等的两栏的方法   使用word分栏功能时,当最后一页内容不能占满整页时,将会出现如下图所示的情况,文字全部集中到了页面左侧。 下面将介绍将最后一页也分成行数相等的两栏的方法。 首先,选中需要分栏的内容,然后单击分栏操作命令(word2003中,该命令在格式菜单中,word2007是在页面布局...
标签: Web开发
Private Sub Command1_Click() WebBrowser1.Navigate "http://localhost/" Timer1.Enabled = TrueEnd Sub Private Sub Timer1_Timer() Dim doc, objhtml As Object Dim i As Integer Dim strhtml As String If Not WebBrowser1.Busy Then Set doc = WebBrowser1.Document i = 0 Set objhtml = doc.body.createtextrange() If Not IsNull(objhtml...
标签: 电脑入门
PowerPoint是我们最常用到的课间展示、资料播放工具。然而很多时候为了方便查看,希望能将PPT打印出来,但如果一页一张A4纸,又显得有些浪费。今天就给大家提供一个小方法,可以批量将8页PPT合并至一张A4 纸中,非常节省资源。 首先,打开需要打印的PPT,为了打印出来的清晰度着想,可以将底板先全部去掉。然后,选择文件-另存为,在文件类型...
制作完幻灯片在播放时出现问题,不能播放下一页幻灯片,你有没有遇到过呢?若有,小编准备了几种可行的方法,大家可以看看:右击幻灯片,在菜单中选择幻灯片切换一项,看下换片方式中的“单击鼠标时”前的勾有没有取消掉,如果取消掉就不能切换到下一页,除非有排练计时,那么请勾上。接着依次执行幻灯片放映-设置放映方式,看看有没...

经验教程

976

收藏

15
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部