Listview databind causes lost of formview Data
Asked Answered
R

1

1

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 ?

Restrain answered 8/11, 2017 at 13:28 Comment(0)
C
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.

Cartload answered 8/11, 2017 at 14:10 Comment(2)
Hum... have you check that the "EnableViewState" is set to true, in the page (and masterpage if you have one) ?Cartload
I think it is by defaultRestrain

© 2022 - 2024 — McMap. All rights reserved.