当前位置: 代码迷 >> ASP.NET >> GridView 分页,该怎么解决
  详细解决方案

GridView 分页,该怎么解决

热度:10342   发布时间:2013-02-25 00:00:00.0
GridView 分页
GridView启用分页之后只在GridView中有 1 2 3 4.....
我想让他分页变成 ”首页 上一页 1 2 3 4..... 下一页 末页“这种格式应该怎么做?????

------解决方案--------------------------------------------------------
看看下面我写的代码:
<asp:GridView DataSourceID="SDS1" Width="600px" ID="GridView1" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PagerSettings-Mode="NextPreviousFirstLast" PagerSettings-NextPageText="下一页" PagerSettings-PreviousPageText="上一页" PagerSettings-FirstPageText="首 页" PagerSettings-LastPageText="尾 页" PageSize="20" Runat="server">
<HeaderStyle BackColor="Orange" ForeColor="White"></HeaderStyle>
<Columns>
<asp:CommandField ItemStyle-ForeColor="Gray" ShowSelectButton="true"/>
<asp:BoundField ItemStyle-ForeColor="#666666" DataField="hostId" HeaderText="电脑编号" SortExpression="hostId"></asp:BoundField>
<asp:BoundField ItemStyle-ForeColor="#666666" DataField="IP" HeaderText="IP" SortExpression="IP"></asp:BoundField>
<asp:BoundField ItemStyle-ForeColor="#666666" DataField="deptName" HeaderText="部门名称" SortExpression="deptName"></asp:BoundField>
<asp:BoundField ItemStyle-ForeColor="#666666" DataField="duty" HeaderText="职务" SortExpression="duty"></asp:BoundField>
<asp:BoundField ItemStyle-ForeColor="#666666" DataField="empName" HeaderText="使用人" SortExpression="empName"></asp:BoundField>
<asp:BoundField ItemStyle-ForeColor="#666666" DataField="itsPassCN" HeaderText="审核否" SortExpression="itsPassCN"></asp:BoundField>
</Columns>
<SelectedRowStyle BackColor="Silver" ForeColor="White" />
</asp:GridView>
------解决方案--------------------------------------------------------
探讨
看看下面我写的代码:
<asp:GridView DataSourceID="SDS1" Width="600px" ID="GridView1" AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" PagerSettings-Mode="NextPreviousFirstLast" PagerSettings-NextPageText="下一页" PagerSettings-PreviousPageText="上一页" PagerSettings-FirstPageText="首 页" PagerSettings-LastPageText="尾 页" PageSize="20" Runat="server">
<HeaderStyle BackColo…

------解决方案--------------------------------------------------------
我给你一个,我自己写的
 <FooterStyle BackColor ="#CCCCC" ForeColor ="Black" />
<RowStyle BackColor ="#EEEEE" ForeColor ="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold ="true" ForeColor ="White" />
<PagerStyle BackColor="#99999" ForeColor ="Black" HorizontalAlign ="Center" />
<HeaderStyle BackColor="#000084" Font-Bold ="true" ForeColor ="White" />
<AlternatingRowStyle BackColor ="Gainsboro" />
<PagerSettings FirstPageText ="首页" LastPageText ="尾页" NextPageText ="下一页" PreviousPageText ="上一页" Mode ="NextPreviousFirstLast" />
------解决方案--------------------------------------------------------
这个需要自己自定义分页了!不过也简单!
如下代码:
C# code
 #region GridView1页码跳转        protected void link_next_Click(object sender, EventArgs e)        {            if (GridView1.PageIndex < GridView1.PageCount)                GridView1.PageIndex++;            CheckPager();            ShowPageIndex();            GridBind();        }        protected void linke_pre_Click(object sender, EventArgs e)        {            if (GridView1.PageIndex > 0)                GridView1.PageIndex--;            CheckPager();            ShowPageIndex();            GridBind();        }        protected void link_frist_Click(object sender, EventArgs e)        {            GridView1.PageIndex = 0;            CheckPager();            ShowPageIndex();            GridBind();        }        protected void link_last_Click(object sender, EventArgs e)        {            GridView1.PageIndex = GridView1.PageCount - 1;            CheckPager();            ShowPageIndex();            GridBind();        }        protected void img_goto_Click(object sender, ImageClickEventArgs e)        {            int page_num = 0;            if (this.txt_pagenum.Text != string.Empty)            {                try                {                    page_num = Convert.ToInt32(this.txt_pagenum.Text);                    if (page_num > 0 && page_num <= GridView1.PageCount)                        this.GridView1.PageIndex = page_num - 1;                }                catch                {                    page_num = this.GridView1.PageIndex;                }                CheckPager();                ShowPageIndex();                GridBind();            }        }        public void ShowPageIndex()        {            if (this.GridView1 != null)            {                this.img_goto.Enabled = true;                if (this.GridView1.PageCount != 0)                {                    pagenum = Convert.ToString(GridView1.PageIndex + 1);//给参数赋页码值                    this.lab_pageindex.Text = Convert.ToString(GridView1.PageIndex + 1) + "/" + this.GridView1.PageCount.ToString();                    this.img_goto.Enabled = true;                }                else                {                    pagenum = Convert.ToString(GridView1.PageIndex + 1);//给参数赋页码值                    this.lab_pageindex.Text = Convert.ToString(GridView1.PageIndex) + "/" + this.GridView1.PageCount.ToString();                    this.img_goto.Enabled = false;                }                //this.txt_pagenum.Text = Convert.ToString(GridView1.PageIndex + 1);                CheckPager();            }            else            {                this.lab_pageindex.Text = "0/0";                this.img_goto.Enabled = false;                this.link_frist.Enabled = false;                this.linke_pre.Enabled = false;                this.link_next.Enabled = false;                this.link_last.Enabled = false;                this.img_goto.Enabled = false;            }        }        private void CheckPager()        {            if (GridView1.PageIndex <= 0)            {                this.link_frist.Enabled = false;                this.linke_pre.Enabled = false;            }            else            {                this.link_frist.Enabled = true;                this.linke_pre.Enabled = true;            }            if (GridView1.PageIndex >= GridView1.PageCount - 1)            {                this.link_next.Enabled = false;                this.link_last.Enabled = false;            }            else            {                this.link_next.Enabled = true;                this.link_last.Enabled = true;            }        }        #endregion