asp:ListView在更新时不会离开编辑模式 [英] asp:ListView doesn't leave edit mode when updated

查看:57
本文介绍了asp:ListView在更新时不会离开编辑模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新面板中使用listView。

在ModulesList_ItemUpdating()中处理的OnItemUpdating事件如下:

  protected   void  ModulesList_ItemUpdating( Object  sender ,ListViewUpdateEventArgs e)
{
// 将数据添加到数据库中
ModulesList.EditIndex = -1;
ModulesList.DataBind();
}





已编辑的数据正在添加到数据库中,但ListView仍处于编辑模式。

在onItemCancelling事件中添加相同的行,效果很好。

  protected   void  ModulesList_ItemCancelling( object  sender,ListViewCancelEventArgs e)
{
ModulesList.EditIndex = -1;
ModulesList.DataBind();
}





我在onItemUpdated事件中插入断点进行调试,editIndex = -1正在执行但是没有反映在网页上。



我缺少什么?我已经尝试了一天以上: - /

解决方案

想出来了。我没有包括

 e.cancel =  true ;在ItemUpdating事件处理程序的末尾

。现在它在更新面板内完美运行。修改后的功能是:

  protected   void  ModulesList_ItemUpdating( Object  sender,ListViewUpdateEventArgs e)
{
// 将数据添加到数据库中
ModulesList.EditIndex = -1;
ModulesList.DataBind();
e.cancel = true ;
}


可能 EditIndex [ ^ ]值为 -1 (表示没有编辑任何项目),这就是你无法设置它的原因。
尝试添加 try ... catch [ ^ ]阻止捕获错误,特别是 ArgumentOutOfRangeException [ ^ ]例外。

<前lang =c#> 受保护 void ModulesList_ItemCancelling( object sender,ListViewCancelEventArgs e)
{
try
{
ModulesList.EditIndex = -1;
ModulesList.DataBind();
}
catch (ArgumentOutOfRangeException ex)
{
// 显示错误消息
}
catch (例外情况)
{
// 显示错误消息
}
}


检查它是否在更新面板之外工作..


I am using a listView inside an update panel.
The OnItemUpdating event, which is handled in ModulesList_ItemUpdating() is as follows:

protected void ModulesList_ItemUpdating(Object sender, ListViewUpdateEventArgs e)
        {
           //add data into the database
           ModulesList.EditIndex = -1;
           ModulesList.DataBind();
        }



The edited data is being added to database, but ListView remains in edit mode.
The same lines, when added in onItemCancelling event, works perfectly.

protected void ModulesList_ItemCancelling(object sender, ListViewCancelEventArgs e)
     {
         ModulesList.EditIndex = -1;
         ModulesList.DataBind();
     }



I inserted breakpoints for debugging in the onItemUpdated event, the editIndex=-1 is executing but not reflected in the web page.

What am I missing? I have been trying for more than a day :-/

解决方案

Figured it out . I hadn''t included

e.cancel=true;

at the end of ItemUpdating event handler. Now it works perfectly inside update panel. The modified function is:

protected void ModulesList_ItemUpdating(Object sender, ListViewUpdateEventArgs e)
        {
           //add data into the database
           ModulesList.EditIndex = -1;
           ModulesList.DataBind();
           e.cancel=true;
        }


Probably EditIndex[^] value is -1 (which indicates that no item is being edited) and that''s why you can''t set it.
Try to add try... catch[^] block to catch errors, especially ArgumentOutOfRangeException[^] exception.

protected void ModulesList_ItemCancelling(object sender, ListViewCancelEventArgs e)
     {
         try
         {
         ModulesList.EditIndex = -1;
         ModulesList.DataBind();
         }
         catch (ArgumentOutOfRangeException ex)
         {
         //show error message         
         }
         catch (Exception ex)
         {
         //show error message
         }
     }


check if it works outside the update panel..


这篇关于asp:ListView在更新时不会离开编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆