我有一个 FormView
,只有当表单不包含数据时,我才想在插入模式下打开它。我尝试过以下 if 语句:
If True Then
If SomeFormView.DataItemCount = 0 Then
SomeFormView.ChangeMode(FormViewMode.Insert)
Else
SomeFormView.ChangeMode(FormViewMode.Edit)
End If
End If
但它在插入中打开是否为空?
最佳答案
在执行该检查之前,您需要等到 FormView
已进行数据绑定(bind),否则您将始终得到“true”(因为它确实有零个项目,直到您将其绑定(bind)到任何数据源)向其提供上述元素)。您可以在 databound 中执行此操作事件,最好是:
SomeFormView_Databound (ByVal sender As Object, ByVal e As EventArgs) Handles SomeFormView.DataBound
{
If SomeFormView.DataItemCount = 0 Then
SomeFormView.ChangeMode(FormViewMode.Insert)
Else
SomeFormView.ChangeMode(FormViewMode.Edit)
End If
}
关于asp.net - 仅当 FormView 为空时才以插入模式打开 FormView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9978929/