Reputation: 261
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?
Upvotes: 2
Views: 5871
Reputation: 11433
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
}
Upvotes: 2