2013-02-06 117 views
1

我有一些代码为我的FormView触发DataBound事件。不幸的是(对于我在做的事情,无论如何),无论是第一次渲染页面还是单击了“编辑”,它都会引发相同的问题。如果它在ItemTemplateEditItemTemplate之间运行,我需要它做不同的事情。迄今为止,我对这个主题的搜索没有结果。有没有一种简单的方法可以沿着if(IsEditItemTemplate)的方向做点什么?有没有办法告诉我的FormView是否处于编辑模式?

回答

1

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."; 
    } 
} 
+0

巨大+1(你的问题)返回到这个问题,并更新了答案。说真的,我们需要更多像你这样的人。保持! –

0

更好地利用合适的功能:

Private Sub EmployeeFormView_ModeChanged(sender As Object, e As EventArgs) 
Handles EmployeeFormView.ModeChanged 
相关问题