0

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>

CodeBehind

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

1 に答える 1

0

私はそれを考え出した。OnPreRender="Pager_PreRender"DataPagerコントロールにを追加しました。以下はその方法です。これまでのところ、意図したとおりに機能しています。

 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;


                    }

                }

        }
于 2013-01-02T23:47:53.563 に答える