Listview 数据绑定导致表单视图数据丢失

Listview databind causes lost of formview Data(Listview 数据绑定导致表单视图数据丢失)
本文介绍了Listview 数据绑定导致表单视图数据丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,通过 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 ?

推荐答案

您是否在页面加载事件中设置了视图状态?

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 数据绑定导致表单视图数据丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)