GridView 的DropDownList分页实现

来源:互联网 发布:java 执行dos命令 编辑:程序博客网 时间:2024/05/19 20:42

<asp:TemplateField HeaderText="选择下载">
 <ItemTemplate>
 <asp:CheckBox runat="server" ID="checked" Checked="false"/>
</ItemTemplate>
</asp:TemplateField>

1.说明:数据列绑定,将GridView增加一个新的列

2.PagerTemplate模板的分页实现:

可以先设计好一个DIV的层:层包括分页按钮,分页显示,DropDownList跳转到第几页

然后放在:PagerTemplate中,

<div style="text-align:left">   
<asp:LinkButton  ID="FirstPage" runat="server"  Text="首页"
ForeColor="#FFFAAA"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>"
CommandArgument="First" CommandName="Page" />

<asp:LinkButton  ID="PuPage" runat="server"  Text="上一页"
CommandArgument="Prev" CommandName="Page" ForeColor="#FFFAAA"
 Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>" />
 
第<asp:Label ID="PageIndex" Text="<%# ((GridView)Container.Parent.Parent).PageIndex+1%>" ForeColor="#FFFAAA" runat="server" />页
/
共<asp:Label ID="Pages" Text="<%# ((GridView)Container.Parent.Parent).PageCount%>"       ForeColor="#FFFAAA" runat="server" />页

<asp:LinkButton  ID="NextPage" runat="server"  Text="下一页" ForeColor="#FFFAAA"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1%>"
CommandArgument="Next" CommandName="Page" />
<asp:LinkButton  ID="LastPage" runat="server"  Text="尾页" ForeColor="#FFFAAA"
Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1%>"
CommandArgument="Last" CommandName="Page" />

<asp:CheckBox runat="server" ForeColor="#FFFAAA" ID="checkAll" Text="全选" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:LinkButton runat="server" ForeColor="#FFFAAA" ID="LoadDownAll" Text="全部下载" />
</div>

绑定说明:

CommandArgument="Prev" CommandName="Page" 相关命令参数,Prev

相关命令:Page

Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=0 %>"//指定页不等于零:显示首页和上一页

Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1%>"//显示下一页和尾

Enabled="<%# ((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1%>"//下一页和上一页的可用设置

CommandArgument="Next" CommandName="Page" />//下页命令参数

CommandArgument="Prev" CommandName="Page">//上一页命令参数

 CommandArgument="First" CommandName="Page" />//首页命令参数

 CommandArgument="Last" CommandName="Page" />//尾页命令参数

是否可用:

DropDownList:的数据绑定:

在GridView的RowDataBound事件中绑定

        int page = this.gdvExercise.PageCount;//共有多少页
        int indexPage = this.gdvExercise.PageIndex;//当前页
        if (e.Row.RowType == DataControlRowType.Pager)
        {
            DropDownList myDropDownList = (DropDownList)e.Row.FindControl("GoPage");//找到DropDownList
            for (int i = 1; i <= page; i++)
            {
                myDropDownList.Items.Add(i.ToString());//加到DropDownList中
                myDropDownList.SelectedIndex = indexPage;//显示设置到当前页
            }
        }


DropDownList :的选择事件

        DropDownList dr = (DropDownList)sender;
        int page = int.Parse(dr.SelectedItem.Text);
        this.gdvExercise.DataSource = exerciseBLL.SelectAllExercise();
        this.gdvExercise.PageIndex = page-1;
        this.gdvExercise.DataBind();


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/anzhiqiang_touzi/archive/2008/04/17/2299725.aspx

原创粉丝点击