首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataPager在分页后丢失数据?

DataPager在分页后丢失数据?
EN

Stack Overflow用户
提问于 2013-01-02 18:38:12
回答 1查看 462关注 0票数 0

我有一个DataPager,用来浏览我的搜索结果。我的DataPager在点击并分页后失去了它的结果,例如,如果我按2-3页,我只会得到像ID这样的标签,而没有数据。

标记

代码语言:javascript
复制
 <asp:ListView runat="server" ID="LVCAdmin">
     <!-- Templates here -->
 </asp:ListView>

<asp:DataPager ID="DataPager1" PagedControlID="LVCAdmin" runat="server">

     <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>

CodeBehind

代码语言:javascript
复制
protected void btnSubmit_Click(object sender, EventArgs e)
{
    string keyword = txtSearch.Text.Trim();

    List<dynamic> Cresults = AdminSearchAll(keyword);

    if (Cresults.Count != 0)
    {    
        LVCAdmin.DataSource = Cresults;
        LVCAdmin.DataBind();

        NoResults.Visible = false;
        LVCAdmin.Visible = true;
    }
    else
    {
        NoResults.Visible = true;

        LVCAdmin.Visible = false;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-02 23:47:53

我想通了。我在我的OnPreRender="Pager_PreRender"控件中添加了一个DataPager。下面是方法。到目前为止,它已经按计划运作了。

代码语言:javascript
复制
 protected void Pager_PreRender(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                   string keyword = txtSearch.Text.Trim();


                    List<dynamic> Cresults = AdminSearchAll(keyword);


                    if (Cresults.Count != 0)
                    {

                        LVCAdmin.DataSource = Cresults;
                        LVCAdmin.DataBind();

                        NoResults.Visible = false;
                        LVCAdmin.Visible = true;
                    }
                    else
                    {

                        NoResults.Visible = true;

                        LVCAdmin.Visible = false;


                    }

                }

        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14127307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档