Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Can we use a DataPager for a DataList?
I've done it but the following exception has occurred !!!

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 

[InvalidOperationException: Control 'DataList1' does not implement IPageableItemContainer.]
   System.Web.UI.WebControls.DataPager.FindPageableItemContainer() +500609
   System.Web.UI.WebControls.DataPager.OnInit(EventArgs e) +33
   System.Web.UI.Control.InitRecursive(Control namingContainer) +333
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Control.InitRecursive(Control namingContainer) +210
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378


The snippet code :

XML
<fieldset>
    <legend align="right">بانک های موجود در دیتا بیس</legend>
    <br />
    <asp:DataList ID="DataList1" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan"
        BorderWidth="1px" CellPadding="2" ForeColor="Black">
        <FooterStyle BackColor="Tan" />
        <AlternatingItemStyle BackColor="PaleGoldenrod" />
        <SelectedItemStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
        <HeaderStyle BackColor="Tan" Font-Bold="True" />
        <ItemTemplate>
            <br />
            <table border="0" align="center" style="width: 93%" cellpadding="3" cellspacing="1">
                <tr>
                    <td>
                        <%# DataBinder.Eval(Container.DataItem, "TextBoxMerchantID") %>
                        <asp:DropDownList ID="DropDownListBankName" runat="server" CssClass="DropDownList">
                            <asp:ListItem Selected="True">ملی</asp:ListItem>
                            <asp:ListItem>پارسیان</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td>
                        نام بانک
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="TextBoxBankAccount" runat="server" CssClass="textbox" MaxLength="50"
                            Text='<%# DataBinder.Eval(Container.DataItem, "TextBoxBankAccount") %>'></asp:TextBox>
                    </td>
                    <td>
                        شماره حساب
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        MerchantID
                    </td>
                    <td>
                        <asp:TextBox ID="TextBoxMerchantID" runat="server" CssClass="textbox" MaxLength="50"
                            Text='<%# DataBinder.Eval(Container.DataItem, "TextBoxMerchantID") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        TerminalID
                    </td>
                    <td>
                        <asp:TextBox ID="TextBoxTerminalID" runat="server" CssClass="textbox" MaxLength="50"
                            Text='<%# DataBinder.Eval(Container.DataItem, "TextBoxTerminalID") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        TransactionKey
                    </td>
                    <td>
                        <asp:TextBox ID="TextBoxTransactionKey" runat="server" CssClass="textbox" MaxLength="50"
                            Text='<%# DataBinder.Eval(Container.DataItem, "TextBoxTransactionKey") %>'></asp:TextBox>
                    </td>
                </tr>
            </table>
            <br />
            <br />
        </ItemTemplate>
    </asp:DataList>
</fieldset>
<br /><br />
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="DataList1">
    <Fields>
        <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowNextPageButton="False"
            ShowPreviousPageButton="True" FirstPageText="<<" LastPageText=">>" NextPageText=">"
            PreviousPageText="<" RenderDisabledButtonsAsLabels="false" />
        <asp:NumericPagerField />
        <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" ShowNextPageButton="True"
            ShowPreviousPageButton="False" RenderDisabledButtonsAsLabels="false" NextPageText=">"
            LastPageText=">>" />
    </Fields>
</asp:DataPager>
Posted
Updated 30-Aug-10 23:37pm
v3

You cannot use DataPager along with DataList as the error says DataList control does not implements IPageableItemContainer.

You can use ListView control instead of DataList.

or

Check Efficient Data Paging with DataList[^].

All the best
 
Share this answer
 
v2
Comments
Mohammad Dayyan 31-Aug-10 10:35am    
Reason for my vote of 5
thanks
I am certain the error is accurate. Perhaps if you post your code ?
 
Share this answer
 
asp.net 2.0 doesnot support Listview
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900