DataPager/listview/sqldatabase作为源 [英] DataPager / listview / sqldatabase as source

查看:91
本文介绍了DataPager/listview/sqldatabase作为源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在制作包含文章列表的页面.我正在使用listview.效果很好.但是我想使用寻呼机.但是有错误,我迷路了.

Hi,
I''m making page with list of articles. I''m using listview for it. It works great. But I want to use pager. But there is error and I''m bit lost.

<asp:ListView runat="server" ID="articlesListView" DataSourceID="SqlDataSource1"

    ItemContainerId="DataSection">
    <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>



这部分没问题.效果很好.但是当我使用datapager时:



This part is ok. It works great. But when I use datapager:

<asp:DataPager ID="DataPagerProducts" runat="server" PagedControlID="articlesListView"

     PageSize="3"  >
     <Fields>
         <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="true" ShowLastPageButton="True" ShowPreviousPageButton="true" />
     </Fields>
 </asp:DataPager>



错误:ID为``articlesListView''的ListView必须具有实现ICollection的数据源,或者如果AllowPaging为true,则可以执行数据源分页.

我不知道该如何移动.我首先找到了有关将其绑定的内容.但是拉力不知道怎么做.拉力需要一些询问来提振我.

非常感谢!



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

I don''t know how to move with it. I found something about databind it first. But rly don''t know how. Rly need some asskick to boost me.

Thanks a lot!

推荐答案

ConnectionStrings:DataServices %> " SelectCommand =" SELECT ID,名称,内容,日期,作者,标签,is_published,section_id,category_id,is_deleted从其中[is_deleted] = 0和is_published = 1的ORDER BY日期DESC的文章 < /asp:SqlDataSource >
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>



这部分没问题.效果很好.但是当我使用datapager时:



This part is ok. It works great. But when I use datapager:

<asp:DataPager ID="DataPagerProducts" runat="server" PagedControlID="articlesListView"

     PageSize="3"  >
     <Fields>
         <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="true" ShowLastPageButton="True" ShowPreviousPageButton="true" />
     </Fields>
 </asp:DataPager>



错误:ID为``articlesListView''的ListView必须具有实现ICollection的数据源,或者如果AllowPaging为true,则可以执行数据源分页.

我不知道该如何移动.我首先找到了有关将其绑定的内容.但是拉力不知道怎么做.拉力需要一些询问来提振我.

非常感谢!



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

I don''t know how to move with it. I found something about databind it first. But rly don''t know how. Rly need some asskick to boost me.

Thanks a lot!


在没有controlID的情况下执行此操作:
do this with out a controlID:
<asp:ListView ID="orders" DataSourceID="dsordes" runat="server">
        <LayoutTemplate>
            <ol id="itemPlaceholder" runat="server"></ol>
            <asp:DataPager ID="pg" PageSize="2" runat="server">
                <Fields>
                    <asp:NextPreviousPagerField

                    ShowFirstPageButton="True"

                    ShowPreviousPageButton="True"

                    ShowNextPageButton="True"

                    ShowLastPageButton="True" />
                    <asp:NumericPagerField />
                </Fields>
            </asp:DataPager>
        </LayoutTemplate>
        
        <ItemTemplate>
            <li>
                <%#Eval("status_id") %>
            </li>
        </ItemTemplate>
    </asp:ListView>


您只需使用控件ID等于itemPlaceholder的布局模板即可.


you just a layout tamplate with a control ID equals to itemPlaceholder.


最好使用ToArray(),因为如果您实际上不需要完整的模板,它会更轻巧列表的功能(例如添加新项目).数组以其他方式实现ICollection(和IList).

试试下面的代码
It is better to use use ToArray() because it''s slightly more lightweight if you don''t actually need full functionality of List (such as adding new items). Arrays implement ICollection (and IList) otherwise.

try the below code
articlesListView.DataSource = urDataSource.ToArray()


这篇关于DataPager/listview/sqldatabase作为源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆