2012-04-02 4 views
2

私はFormViewを挿入モードで開きますフォームにデータが含まれていない場合のみ。私は次のif文を試しました:フォームが空の場合にのみ挿入モードで開く

If True Then 
If SomeFormView.DataItemCount = 0 Then 
    SomeFormView.ChangeMode(FormViewMode.Insert) 
Else 
    SomeFormView.ChangeMode(FormViewMode.Edit) 
End If 


End If 

空であるかどうかは、挿入されていないのでしょうか?

答えて

2

このチェックを行う前にFormViewがデータバインドされるまで待つ必要があります。それ以外の場合は、常に「true」になります(項目をゼロにすると、 。あなたが好ましく、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 
} 
+0

おかげで:)私はそれがPage_Loadの – user1055487

+0

にロードしていた私は、私は助けることがうれしい、@ user1055487 =) – jadarnel27

関連する問題