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