GridView 的DropDownList分页实现

<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();

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值