DataPager与Listview无法正常工作

时间:2012-05-02 19:17:38

标签: asp.net listview datapager

是我的aspx页面的html

   <asp:ListView ID="lstviewInvoiceReport" runat="server">
        <LayoutTemplate>
            <table style="font-size: medium; font-family: Times New Roman">
                <tr>
                    <th>
                        Date
                    </th>
                    <th>
                        Biller
                    </th>
                    <th>
                        Customer
                    </th>
                    <th>
                        Total
                    </th>
                    <th>
                        Owing
                    </th>
                    <th>
                        Paid
                    </th>
                </tr>
                <tr>

                </tr>
                <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    <asp:Label runat="server" ID="lblDate"><%#Eval("InvoiceDate") %></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblBillerName"><%#Eval("BillerName") %></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblCustName"><%#Eval("CustName") %></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblTotal"><%#Eval("InvoiceTotal") %></asp:Label>
                </td>
                <td>
                    <asp:Label runat="server" ID="lblOwing"><%#Eval("InvoiceOwing") %></asp:Label>
                </td>
            </tr>
        </ItemTemplate>
    </asp:ListView>
    <br />
    <asp:DataPager ID="DataPager1" runat="server" PagedControlID="lstviewInvoiceReport"
        PageSize="2">
        <Fields>
            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False"
                ShowPreviousPageButton="False" />
            <asp:NumericPagerField />
            <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False"
                ShowPreviousPageButton="False" />
        </Fields>
    </asp:DataPager>

并在代码背后:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        dt = objBllinvoice.GetInvoiceStatement(6, 3, "20120404", "20120407");
        lstviewInvoiceReport.DataSource = dt;
        lstviewInvoiceReport.DataBind();
    }
}

我绑定listview与datatable工作正常,但是当我分页listview时 a)我需要点击每个按钮加倍才能使其正常工作。 b)listview中的数据没有根据分页更新。

请在这种情况下帮助我。感谢

2 个答案:

答案 0 :(得分:3)

使用数据管理器时,必须在PreRender中进行数据绑定。您目前正在Page_Load

中进行数据绑定

答案 1 :(得分:1)

尝试将您的数据绑定到PagePropertiesChanged事件中,如下所示:

protected void lstviewInvoiceReport_PagePropertiesChanged(object sender, EventArgs e)
        {
            BindData();
        }
相关问题