Listview databind causes lost of formview Data

2019-03-01 11:26发布

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条回答
贪生不怕死
2楼-- · 2019-03-01 12:03

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.

查看更多
登录 后发表回答