ListView的使用DataPager的不工作 [英] ListView with DataPager not working

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

问题描述

这一切我读过,它似乎是添加分页ListView控件应该是死的简单,但它不是为我工作。加入ListView和DataPager的控件到窗体和它们连接在一起后,我得到很奇怪的行为。 DataPager的正确限制ListView的页面大小,但点击分页按钮不会影响到ListView中的。分页按钮似乎认为他们正在做他们的工作,作为最后一个按钮是无效的,当你去到最后一页,等等,但在ListView从不改变。此外,它需要两次点击就DataPager的得到它做任何事情,即点击一次最后什么也不做,但点击它第二次导致DataPager的作为,如果最后一页被选中反应。

我能想到的唯一的事情就是我在运行时绑定的DataSource(对LINQ的对象),不使用LinqDataSource控件或任何东西。有没有人见过这种行为?难道我做错了什么?这里的code我使用的是:

 < ASP:DataPager的ID =HistoryDataPager=服务器PagedControlID =HistoryListView每页=10>
    <&领域GT;
        < ASP:接下来previousPagerField按钮类型=按钮ShowFirstPageButton =真ShowLastPageButton =真/>
    < /场>
< / ASP:DataPager的>< ASP:ListView控件ID =HistoryListView=服务器>
    ...
< / ASP:的ListView>

在code-背后:

 保护小组的Page_Load(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手Me.Load    如果没有的IsPostBack然后
        HistoryListView.DataSource =从X在myContext.myTables ...
        的DataBind()
    万一结束小组


解决方案

看一看的ListViewPagedDataSource。

 私人ListViewPagedDataSource GetProductsAsPagedDataSource(DataView的DV)
{
//通过PagedDataSource限制的结果
ListViewPagedDataSource pagedData =新ListViewPagedDataSource();
pagedData.DataSource = DV;
pagedData.MaximumRows = dv.Table.Rows.Count;
pagedData.TotalRowCount = dpTop.PageSize;如果(的Request.QueryString [dpTop.QueryStringField]!= NULL)
  pagedData.StartRowIndex =(Convert.ToInt32(的Request.QueryString [dpTop.QueryStringField]) - 1)* dpTop.PageSize;
其他
  pagedData.StartRowIndex = 0;返回pagedData;
}

不过,我看最后一页的一个问题。 DataPager的跳回到第一页,但显示的数据是最后一页。

From everything I've read, it seemed that adding paging to a ListView control should be dead simple, but it's not working for me. After adding the ListView and DataPager controls to the form and wiring them together, I'm getting very odd behavior. The DataPager correctly limits the ListView's page size, but clicking the paging buttons doesn't affect the ListView at all. The paging buttons seem to think they are doing they're job, as the last button is disabled when you go to the last page, etc., but the ListView never changes. Also, it takes two clicks on the DataPager to get it to do anything, i.e., clicking on Last once does nothing, but clicking it a second time causes the DataPager to react as if the last page is now selected.

The only thing I can think of is that I'm binding the DataSource at runtime (to a LINQ object), not using a LinqDataSource control or anything. Has anyone seen this behavior? Am I doing something wrong? Here's the code I'm using:

<asp:DataPager ID="HistoryDataPager" runat="server" PagedControlID="HistoryListView" PageSize="10">
    <Fields>
        <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="true" ShowLastPageButton="true" />
    </Fields>
</asp:DataPager>

<asp:ListView ID="HistoryListView" runat="server">
    ...
</asp:ListView>

In the code-behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
        HistoryListView.DataSource = From x in myContext.myTables ...
        DataBind()
    End If

End Sub

解决方案

Take a look at the ListViewPagedDataSource.

private ListViewPagedDataSource GetProductsAsPagedDataSource(DataView dv)
{
// Limit the results through a PagedDataSource
ListViewPagedDataSource pagedData = new ListViewPagedDataSource();
pagedData.DataSource = dv;
pagedData.MaximumRows = dv.Table.Rows.Count;
pagedData.TotalRowCount = dpTop.PageSize;

if (Request.QueryString[dpTop.QueryStringField] != null)
  pagedData.StartRowIndex = (Convert.ToInt32(Request.QueryString[dpTop.QueryStringField]) - 1) * dpTop.PageSize;
else
  pagedData.StartRowIndex = 0;

return pagedData;
}

Though, I have a problem viewing the last page. The DataPager jumps back to the first page, but the data displayed is the last page.

这篇关于ListView的使用DataPager的不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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