【问题标题】:DataPager losing data after paging?分页后DataPager丢失数据?
【发布时间】:2013-01-02 18:38:12
【问题描述】:

我有一个DataPager,我用它来翻阅我的搜索结果。我的 DataPager 在我点击并分页其中一些后丢失了结果,例如,如果我翻页 2-3 次,我将只得到 ID 等标签而没有数据。

标记

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

代码隐藏

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

【问题讨论】:

    标签: c# asp.net linq ef-code-first


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 2012-11-24
      相关资源
      最近更新 更多