我有一个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;
}
}发布于 2013-01-02 23:47:53
我想通了。我在我的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;
}
}
}https://stackoverflow.com/questions/14127307
复制相似问题