打开插入模式一个FormView只有当它是空的 [英] Open a FormView in insert mode only when it's empty
问题描述
我有一个 FormView控件
,我想在插入模式下打开的仅在的格式不包含任何数据。我试过以下if语句:
I have a FormView
which I would like to open in insert mode only if the form contains no data. I've tried the following if statement:
If True Then
If SomeFormView.DataItemCount = 0 Then
SomeFormView.ChangeMode(FormViewMode.Insert)
Else
SomeFormView.ChangeMode(FormViewMode.Edit)
End If
End If
但它在插入打开是否为空或不?
but it opens in insert whether empty or not?
推荐答案
您需要等到 FormView控件
这样做检查之前,已经被数据绑定,否则你将永远得到真(因为它有为零的项目,直到你把它绑定到任何数据源提供它说项目)。你可以在做到这一点的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.databound.aspx\"相对=nofollow>数据绑定事件,preferably:
You need to wait until the FormView
has been databound before doing that check, otherwise you'll always get "true" (because it does have zero items until you bind it to whatever data source is providing it with said items). You could do this in the databound event, preferably:
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
}
这篇关于打开插入模式一个FormView只有当它是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!