Listview databind causes formview data loss

inside my code, after researching through Formview, I need to call listview.databind, and this makes it impossible to receive Formview data, even if it still appears on the screen. this is my code

protected void DemandeSearchFormView_ItemInserting(object sender, FormViewInsertEventArgs e) { ListView listview = (ListView)panelPagination.FindControl("listdeclarations"); ViewState["search"] = "search"; listview.DataBind(); } 

databind () usually calls 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"] is null, I don’t know why ?? databind () seems to reload the page or something like that. Does anyone have an idea how to handle this?

+1
source share
1 answer

Is the view mode set in the page load event?

If so, I think you should add a condition to your Page_Load event:

 private void Page_Load() { if (!IsPostBack) { } } 

this prevents data reloading on this event if a message is sent.

+1
source

All Articles