2017-12-20 21 views
0

私の問題を説明しようとしています。Multiview Navigation Event Handlerで複数のFORループを管理するには

複数のGridViewコントロールがあり、それぞれに独自のチェックボックスとテキストボックスがあります。

ユーザーは、チェックボックスをオンにするか、すべてのテキストボックスにデータを入力する必要があります。

チェックボックスがオフで、特定のグリッドビューコントロール内のテキストボックスが空の場合、ユーザーがマルチビューコントロールのNEXTボタンをクリックすると、エラーが発生します。

次のコードは、NEXTナビゲーションボタンのボタンクリックイベント内の2つのFORループを示しています。

最初のGridview1 FORループはうまく機能します。チェックボックスがオフで、テキストボックスが空の場合は、警告メッセージが表示され、次のページに移動することはできません。

ただし、チェックボックスがオンになっているか、テキストボックスにデータが入力されている場合は、次のページに移動できます。

問題はgrvspouse gridviewコントロールの2番目のFORループです。

チェックボックスをオフにしてテキストボックスを空にすると、警告ボックスにチェックボックスまたはテキストボックスにデータを入力する必要があるというメッセージが表示されます。これは問題ありません。しかし、問題はユーザーがまだ次のページに移動しているということです。

BTN_NEXTナビゲーションイベントハンドラ内で複数のFORループを処理する方法はありますか?

Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs) 

    'If the message failed at some point, let the user know 
    For Each row As GridViewRow In Gridview1.Rows 
     Dim namesource As TextBox = TryCast(row.FindControl("txtsourcename"), TextBox) 
     Dim nmesource As String = namesource.Text 
     Dim addresssource As TextBox = TryCast(row.FindControl("txtsourceaddress"), TextBox) 
     Dim addrsource As String = addresssource.Text 
     Dim incomesource As TextBox = TryCast(row.FindControl("txtsourceincome"), TextBox) 
     Dim incmsource As String = incomesource.Text 
     Dim ckb As CheckBox = TryCast(row.FindControl("grid1Details"), CheckBox) 
     Dim checkb As Boolean = ckb.Checked 
     If checkb = False AndAlso nmesource = "" AndAlso addrsource = "" AndAlso incmsource = "" Then 
      ClientScript.RegisterStartupScript([GetType](), "Confirm", "jAlert('Please enter values on all textboxes or check the checkbox next to each textbox!');", True) 
     Else 
      myMultiView.ActiveViewIndex += 1 
      lblResult.Visible = True 
     End If 
    Next 

    For Each row As GridViewRow In grvspouse.Rows 
     Dim namespouse As TextBox = TryCast(row.FindControl("txtspousename"), TextBox) 
     Dim nmespouse As String = namespouse.Text 
     Dim addressspouse As TextBox = TryCast(row.FindControl("txtspouseaddress"), TextBox) 
     Dim addrspouse As String = addressspouse.Text 
     Dim incomespouse As TextBox = TryCast(row.FindControl("txtspouseincome"), TextBox) 
     Dim incmspouse As String = incomespouse.Text 
     Dim ckb2 As CheckBox = TryCast(row.FindControl("spouseDetails"), CheckBox) 
     Dim checkc As Boolean = ckb2.Checked 
     If checkc = False AndAlso nmespouse = "" AndAlso addrspouse = "" AndAlso incmspouse = "" Then 
      ClientScript.RegisterStartupScript([GetType](), "Confirm", "jAlert('Please enter values on all textboxes or check the checkbox next to each textbox!');", True) 
     Else 
      myMultiView.ActiveViewIndex += 1 
      lblResult.Visible = True 
     End If 
    Next 

End Sub 

[編集]は、あなたがそのようにコード化されたため、この問題に直面している

enter image description here

答えて

0

....最も簡単な修正はSTRING VARIABLEオブジェクトを作成することで、各クリックでしまいます、プログラムはVARIABLEに希望の値をチェックし、値が一致すれば次のフォームに移動します。

'Create a VARIABLE named HITCOUNT and keep the value empty at first. 
    Public class MyProject 
    Dim HITCOUNT as string = "" 


If HITCOUNT = "" Then 
For Each row As GridViewRow In Gridview1.Rows 
Dim namesource As TextBox = TryCast(row.FindControl("txtsourcename"), TextBox) 
Dim nmesource As String = namesource.Text 
Dim addresssource As TextBox = TryCast(row.FindControl("txtsourceaddress"), TextBox) 
Dim addrsource As String = addresssource.Text 
Dim incomesource As TextBox = TryCast(row.FindControl("txtsourceincome"), TextBox) 
Dim incmsource As String = incomesource.Text 
Dim ckb As CheckBox = TryCast(row.FindControl("grid1Details"), CheckBox) 
Dim checkb As Boolean = ckb.Checked 
If checkb = False AndAlso nmesource = "" AndAlso addrsource = "" AndAlso incmsource = "" Then 
    ClientScript.RegisterStartupScript([GetType](), "Confirm", "jAlert('Please enter values on all textboxes or check the checkbox next to each textbox!');", True) 
Else 
    myMultiView.ActiveViewIndex += 1 
    lblResult.Visible = True 
End If 
Next 
HITCOUNT = "1" 'adding an integer value of 1(you can add anything) 
End if 

If HITCOUNT = "1" then 
For Each row As GridViewRow In grvspouse.Rows 
Dim namespouse As TextBox = TryCast(row.FindControl("txtspousename"), TextBox) 
Dim nmespouse As String = namespouse.Text 
Dim addressspouse As TextBox = TryCast(row.FindControl("txtspouseaddress"), TextBox) 
Dim addrspouse As String = addressspouse.Text 
Dim incomespouse As TextBox = TryCast(row.FindControl("txtspouseincome"), TextBox) 
Dim incmspouse As String = incomespouse.Text 
Dim ckb2 As CheckBox = TryCast(row.FindControl("spouseDetails"), CheckBox) 
Dim checkc As Boolean = ckb2.Checked 
If checkc = False AndAlso nmespouse = "" AndAlso addrspouse = "" AndAlso incmspouse = "" Then 
    ClientScript.RegisterStartupScript([GetType](), "Confirm", "jAlert('Please enter values on all textboxes or check the checkbox next to each textbox!');", True) 
Else 
    myMultiView.ActiveViewIndex += 1 
    lblResult.Visible = True 
End If 
Next 
HITCOUNT="2" 
End if 

    'and move on and on 

これはただ一つの方法ですと、おそらく

enter image description here

+0

コメントをあなたはしたくはこの1つを使用していないso.If、やるだけのコメントと私は別の解決策を投稿しますするには他の多くの方法が最速one.Thereあります議論の延長ではありません。この会話は[チャットに移動]されています(http://chat.stackoverflow.com/rooms/161576/discussion-on-answer-by-zack-raiyan-how-do-i-manage-multiple-for-loops- in-multiv)。 –

関連する問題