Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i validate to see if the same selected item is selected out of

Status
Not open for further replies.

miscluce

MIS
Joined
Oct 4, 2007
Messages
149
Location
US

I almost have this but not yet. Need some help from teh experst.
:)

All five drop downs must also be false also. and I also need to check whether or not the selected index is > 0 first because you can have duplicate nonselected dropdowns.

Only the teams selected can be duplicates but I can have duplicate Null values.

This is what I have so far..

Dim flag As Boolean = False
''''''''''validate if the same two teams are picked
If ddlPick1.SelectedItem.Value = ddlPick2.SelectedItem.Value Then
'First& second are equal
If ddlPick2.SelectedItem.Value = ddlPick3.SelectedItem.Value Then
' first,second,third are equal
If ddlPick3.SelectedItem.Value = ddlPick4.SelectedItem.Value Then
' first,second,third,forth are equal
If ddlPick4.SelectedItem.Value = ddlPick5.SelectedItem.Value Then
' first,second,third,forth,fifth are equal
flag = True
End If
End If
End If
End If
If (flag) = False Then

'give error message
lblSubmitError.Text = "You have duplicate picks. Please pick again."
Exit Sub
End If
 
I am trying to validate duplicate selections from five drop down lists. They cant have dupilcates from either one. but they can allow either one of them not selected.
 
As I see it, flag will only be true if all the dropdowns are the same and you want it to be false if any of the dropdowns match - yeah?

If so, you need to test each dropdown with each other. e.g.
Code:
If ddl1.SelectedValue = ddl2.SelectedValue Or ddl1.SelectedValue = ddl3.SelectedValue Or ddl1.SelectedValue = ddl4.SelectedValue Or ddl1.SelectedValue = ddl5.SelectedValue Or ddl2.SelectedValue = ddl3.SelectedValue Or ddl2.SelectedValue = ddl4.SelectedValue Or ddl2.SelectedValue = ddl5.SelectedValue Or ddl3.SelectedValue = ddl4.SelectedValue Or ddl3.SelectedValue = ddl5.SelectedValue Or ddl4.SelectedValue = ddl5.SelectedValue Then
flag = False
End If

(Code not tested) then just expand that structure to include more conditions as required. Maybe else if to make it more readble...

Hope that helps
Rob
 
yeah, I know Ican do it that way. I was trying to be more effecient. I would have 20 conditions this way. Not the best way to do it. I am working on a loop method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top