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