asp.net(C#) listview databind - pager problem

Vývojová prostředí, aplikace, skripty, http://www... síťové programy, internet, sdílení...
Odpovědět
tmaven
Začátečník
Začátečník
Registrován: 26. kvě 2007
Bydliště: Havířov/Ostrava/Brno
Kontaktovat uživatele:

asp.net(C#) listview databind - pager problem

Příspěvek od tmaven »

cao,
mam takovy "mensi" problem. Pouzivam listview(itemtemplate) pro vytvoreni newsek na hlavni strance. Vse funguje jak ma. Problem ale nastava, kdyz potrebuju pridat pager.

Vyhodi mi to error:

Kód: Vybrat vše

ListView with id 'articlesListView' must have a data source that either implements ICollection or can perform data source paging if AllowPaging is true.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: ListView with id 'articlesListView' must have a data source that either implements ICollection or can perform data source paging if AllowPaging is true.

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.
Co jsem pochopil, tak allowpaging neni implementovano normalne v listview. Takze ty data z sql musim nejak hodit do formatu "ICollection". Tady je ale problem, ze nevim jak. Takze bych potreboval poradit.

Kod:

Kód: Vybrat vše

                    <asp:ListView runat="server" ID="articlesListView" DataSourceID="SqlDataSource1">
                    <LayoutTemplate>                        
                        <asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
                    </LayoutTemplate>

                    <ItemTemplate>
                        <div class="article">
                            <div class="article-headline">
                                <b><asp:Label ID="nameOfArticle" runat="Server" Text='<%# Eval("name") %>' CssClass="article-headline-text"/></b><br />
                            </div>
                            <div class="article-content">
                                <asp:Label ID="contentOfArticle" runat="Server" Text='<%# Eval("content").ToString().Substring(0, Math.Min(Eval("content").ToString().Length, 300)) + "..." %>' CssClass="article-content-text"/><br/><br/>
                            </div>
                            <div class="article-info">
                                <asp:Label ID="dateOfCreation" runat="Server" Text='<%# Eval("date", "{0:d}") %>' CssClass="article-info-text"/><br/><br/>
                                <asp:Label ID="author" runat="server" Text='<%# Eval("author") %>' CssClass="article-info-text"/><br/><br/>
                                <b><asp:HyperLink ID="sendIdForArticle" runat="server" Text="Číst vše" NavigateUrl='<%#"Article.aspx?id=" + Eval("id") %>' CssClass="article-info-link" /></b><br/>
                            </div>                       
                        </div>
                    </ItemTemplate>
                </asp:ListView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataReader" 
                    ConnectionString="<%$ ConnectionStrings:DataServices%>" SelectCommand="SELECT id, name, content, date, author, tags, is_published, section_id, category_id, is_deleted FROM articles WHERE [is_deleted]=0 AND is_published=1 ORDER BY date DESC">
                </asp:SqlDataSource>


    <asp:DataPager ID="DataPagerProducts" runat="server" PagedControlID="articlesListView"
        PageSize="3" >
        <Fields>
            <asp:NextPreviousPagerField ShowFirstPageButton="True" 
                                        ShowNextPageButton="true" 
                                        ShowLastPageButton="True" 
                                        ShowPreviousPageButton="true" />
        </Fields>
    </asp:DataPager>
ASUS ROG STRIX B550-I GAMING ~ AMD Ryzen 7 5800X3D ~ GeForce RTX™ 3070 Ti GAMING OC 8G ~ G.SKill Trident Z RGB 32GB (2x16GB) DDR4 3600 CL17 ~ Corsair SF750W ~ Samsung 980 PRO 1TB ~ Cooler Master MasterBox NR200P ~ Scythe Fuma 2 ~ Dell S2721DGF + BenQ XL2411Z + Samsung 2233RZ ~ www.flyingbbq.cz - Blog o BBQ!
Odpovědět

Zpět na „Programování a web“