C# 数据寻呼器在寻呼后丢失数据?
我有一个C# 数据寻呼器在寻呼后丢失数据?,c#,asp.net,linq,ef-code-first,C#,Asp.net,Linq,Ef Code First,我有一个DataPager,用来翻阅搜索结果。我的DataPager在我点击并翻页其中的一些内容后会丢失它的结果,例如,如果我翻页2-3次,我只会得到像ID这样的标签,而没有数据 标记: <asp:ListView runat="server" ID="LVCAdmin"> <!-- Templates here --> </asp:ListView> <asp:DataPager ID="DataPager1" PagedControl
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;
}
}
代码隐藏:
<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;
}
}
protectedvoid btnSubmit\u单击(对象发送方,事件参数e)
{
string关键字=txtSearch.Text.Trim();
List Cresults=AdminSearchAll(关键字);
如果(Cresults.Count!=0)
{
LVCAdmin.DataSource=Cresults;
LVCAdmin.DataBind();
NoResults.Visible=false;
LVCAdmin.Visible=true;
}
其他的
{
NoResults.Visible=true;
LVCAdmin.Visible=false;
}
}
我想出来了。我在DataPager控件中添加了一个OnPreRender=“Pager\u 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;
}
}
}
protectedvoid Pager\u PreRender(对象发送方,事件参数e)
{
如果(iPostBack)
{
string关键字=txtSearch.Text.Trim();
List Cresults=AdminSearchAll(关键字);
如果(Cresults.Count!=0)
{
LVCAdmin.DataSource=Cresults;
LVCAdmin.DataBind();
NoResults.Visible=false;
LVCAdmin.Visible=true;
}
其他的
{
NoResults.Visible=true;
LVCAdmin.Visible=false;
}
}
}