DataPager控件通过URL传参保存当前页码

从ListView当前页Default.aspx点击修改超链接,跳转到修改页面Mod.aspx

<asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource1" onsorting="ListView1_Sorting" ondatabound="ListView1_DataBound" >
    <LayoutTemplate> 
    <table> 
        <thead> 
            <tr> 
                <th>修改</th> 
            </tr>
        </thead>
        <tbody> 
            <asp:PlaceHolder runat="server" ID="itemPlaceholder"> </asp:PlaceHolder> 
        </tbody>
   </table> 
   </LayoutTemplate> 
   <ItemTemplate> 
   <tr> 
        <td>
            <a href='Mod.aspx?customerid=<%# Eval("CustomerID") %>&p=<%=Data_Pager_Index %>'>修改</a>
        </td> 
   </tr> 
   </ItemTemplate> 
</asp:ListView>                    

 

 上面html代码中,参数customerid是当前行ID,参数p是当前页码,Data_Pager_Index是后台代码 Default.aspx.cs中的字段,在每次通过点击DataPager分页控件使ListView控件绑定数据后,由事件 ListView1_DataBound中修改并保存当前页码:

protected void ListView1_DataBound(object sender, EventArgs e)
        {
            Data_Pager_Index = DataPager1.TotalRowCount > 0 ? (DataPager1.StartRowIndex / DataPager1.PageSize + 1) : 0;
        }

在修改页面操作完成后,在提交或返回按钮中将获取的Data_Pager_Index页码传递回Default.aspx:

protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx?page=" + P + "");
        }

在Default.aspx页面中获取page参数的值,通过自定义方法SetPagerIndex()设置DataPager参数:

protected void SetPagerIndex()
        {
            int startindex = (Data_Pager_Index - 1) * DataPager1.PageSize;
            int pagesize = DataPager1.PageSize;
            DataPager1.SetPageProperties(startindex, pagesize, true);
            ListView1.DataBind();
        }

该方法中通过DataPager控件的SetPageProperties()方法设置当前页起始索引startindex及当前页显示记录pagesize,是否绑定数据中设置为true,然后绑定数据,就可返回跳转到修改页Mod.aspx之前的页面。

转载于:https://www.cnblogs.com/xuq23/p/3620231.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值