ListView加DataPager在不使用LinqDataSource(DataSourceID)时如何动态分页



ListView加DataPager在不使用LinqDataSource(DataSourceID)时如何动态分页 ,
采用后端代码方式实现listview的分页

参考

http://www.cnblogs.com/kingjiong/archive/2008/10/16/1312395.html

ASP.NET 3.5中新增的ListView、DataPager与LinqDataSource控制项可说是绝佳拍档,
不过当你不使用LinqDataSource的时候会发生一个小问题,就是当你在第一次点选DataPager
中的页码时并不会跟着跳页,而点选第二次的时候才会正常运作!所谓的「不使用LinqDataSource
的时候」是指你的资料来源的取得可能是写在Code Behind中或是使用ObjectDataSource或
SqlDataSource控制项,例如:所谓的「不使用LinqDataSource的时候」是指你的资料来源的取


<div>
        <asp:ListView ID="ListView1" runat="server" OnPagePropertiesChanging="ListView1_PagePropertiesChanging">

            <EmptyDataTemplate>
                <table runat="server" style="">
                    <tr>
                        <td>未返回数据。</td>
                    </tr>
                </table>
            </EmptyDataTemplate>

            <ItemTemplate>
                <tr style="">
                    <td>

                        <a href='PorductEdit.aspx?pid=<%# Eval("ID") %>'>编辑</a>

                    </td>
                    <td>
                        <asp:Label ID="WPMCLabel" runat="server" Text='<%# Eval("WPMC") %>' />
                    </td>
                    <td>
                        <asp:Label ID="KCSLLabel" runat="server" Text='<%# Eval("KCSL") %>' />
                    </td>
                    <td>
                        <asp:Label ID="DJLabel" runat="server" Text='<%# Eval("DJ") %>' />
                    </td>
                    <td>
                        <img src='Images/<%# Eval("TPDZ") %>' alt="无图" width="32px" height="32px" />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <table runat="server">
                    <tr runat="server">
                        <td runat="server">
                            <table id="itemPlaceholderContainer" runat="server" border="0" style="">
                                <tr runat="server" style="">
                                    <th runat="server">ID</th>
                                    <th runat="server">WPMC</th>
                                    <th runat="server">KCSL</th>
                                    <th runat="server">DJ</th>
                                    <th runat="server">TPDZ</th>
                                </tr>
                                <tr id="itemPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr id="Tr1" runat="server">
                        <td id="Td1" runat="server" style="">
                            <asp:DataPager ID="DataPager1" runat="server">
                                <Fields>
                                    <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                    <asp:NumericPagerField />
                                    <asp:NextPreviousPagerField ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                </Fields>
                            </asp:DataPager>
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>

        </asp:ListView>
    </div>



C#


 protected void Page_Load(object sender, EventArgs e)
        {
            ListView1.DataSource = ProductManager.GetAll();
            ListView1.DataBind();
        }

        protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            ListView srcListView = sender as ListView;
            var dp = srcListView.FindControl("DataPager1") as DataPager;
            dp.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            srcListView.DataBind();
        }





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值