Listview databind causes lost of formview Data

杀马特。学长 韩版系。学妹 提交于 2019-12-04 05:00:18

问题


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();

    }

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");

}

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 ?


回答1:


Do you set the viewstate in your page load event?

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.



来源:https://stackoverflow.com/questions/47180999/listview-databind-causes-lost-of-formview-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!