我有一个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;
}
}
答案 0 :(得分:0)
我明白了。我在我的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;
}
}
}