ListView Databind导致FormView数据丢失 [英] Listview databind causes lost of formview Data
问题描述
在我的代码内,通过Formview进行研究后,我需要调用listview.databind,这使得即使在屏幕上仍然出现Formview数据也无法获得. 这是我的代码
within my code , after a research via a Formview , I need to call the listview.databind and this makes impossible to get the Formview data , even if in the screen they still appear . this is my code
protected void DemandeSearchFormView_ItemInserting(object sender, FormViewInsertEventArgs e)
{
ListView listview = (ListView)panelPagination.FindControl("listdeclarations");
ViewState["search"] = "search";
listview.DataBind();
}
databind()通常调用此方法
the databind() normally call this method
public DeclarationGeneraleBean RechercheByCritere()
{
DeclarationGeneraleBean declarationBean = new
DeclarationGeneraleBean();
declarationBean.IdService = (int) Session["idService"];
if (ViewState["search"] != null)
{
TextBox numOrdre =
(TextBox)DemandeSearchFormView.FindControl("numtxt");
}
ViewState ["search"]为null,我不知道为什么?似乎databind()为页面或类似内容重新充电. 有谁知道如何处理吗?
the ViewState["search"] is null , I dont know why ?? it seems that the databind() recharge the page or something like this . Have any one an idea how to deal with this ?
推荐答案
您是否在页面加载事件中设置了viewstate?
Do you set the viewstate in your page load event?
如果是,我认为您应该在Page_Load事件中添加一个条件:
If yes, i think you should add a condition in your Page_Load event :
private void Page_Load()
{
if (!IsPostBack)
{
}
}
如果提交了帖子,则防止在此事件上重新加载数据.
it prevent the data to be reloaded on this event, if a post is submited.
这篇关于ListView Databind导致FormView数据丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!