有没有办法判断我的FormView是否处于编辑模式?

时间:2013-02-06 21:49:03

标签: asp.net formview

我的FormView上有一些代码可以触发DataBound事件。不幸的是(无论如何,无论是第一次渲染页面还是我刚刚点击编辑,它都会触发)。如果它在ItemTemplate经文EditItemTemplate上运行,我需要它做一些不同的事情。到目前为止,我对这个问题的搜索没有结果。是否有一种简单的方法可以按照if(IsEditItemTemplate)

的方式做某事

2 个答案:

答案 0 :(得分:2)

FormView.CurrentMode是你的朋友

更多解释here


来自引用网站:

Mode                   Description
FormViewMode.Edit      The FormView control is in edit mode, which allows the 
                       user to update the values of a record.
FormViewMode.Insert    The FormView control is in insert mode, which allows the 
                       user to add a new record to the data source.
FormViewMode.ReadOnly  The FormView control is in read-only mode, which is the 
                       normal display mode.

示例代码

void EmployeeFormView_OnPageIndexChanging(Object sender, FormViewPageEventArgs e)
{
    // Cancel the paging operation if the user attempts to navigate 
    // to another record while the FormView control is in edit mode. 
    if (EmployeeFormView.CurrentMode == FormViewMode.Edit)
    {
        e.Cancel = true;
        MessageLabel.Text = 
          "Please complete the update before navigating to another record.";
    }
}

答案 1 :(得分:0)

更好地使用正确的功能:

 Private Sub EmployeeFormView_ModeChanged(sender As Object, e As EventArgs)
 Handles EmployeeFormView.ModeChanged