Drop Down Validation

hi guys,
i am making a simple form for my job and it has two drop down menus and a submit button,
the user has to either not select anything from the drop down and click submit to get the results ( * ) from a database, or if he/she select a value for one drop down, he/she has to select the other drop down also for it to work, its a all or none scenario.
here is the code that i have now,,,
anyone can help with the validation code on it?
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="123px">
            <asp:ListItem Selected="True">*</asp:ListItem>
        <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" Width="123px">
            <asp:ListItem Selected="True">*</asp:ListItem>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
Who is Participating?
RamuncikasConnect With a Mentor Commented:
correction -  you don't need new line after "OR" or add the underline sign "_" if you want to split IF statement inti two lines:

If (DropDownList1.SelectedValue="*" and DropDownList2.SelectedValue<>"*") OR _
(DropDownList1.SelectedValue<>"*" and DropDownList2.SelectedValue="*") Then
   'report error
   'query database and show results
End if
Remove the Autopostback from dropdown lists'. They are not needed here (I think)

then in Button1_Click event:

If DropDownList1.SelectedValue="*" and DropDownList2.SelectedValue<>"*" OR
DropDownList1.SelectedValue<>"*" and DropDownList2.SelectedValue="*" Then
   'report error
   'query database and show results
End if
djsoltanAuthor Commented:
hi ramuncikas,
thanks for the help,
it gives me a compiler error,, any idea why?
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30201: Expression expected.

Source Error:


Line 2:  
Line 3:  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Line 4:          If DropDownList1.SelectedValue="*" and DropDownList2.SelectedValue<>"*" OR
Line 5:  DropDownList1.SelectedValue<>"*" and DropDownList2.SelectedValue="*" Then
Line 6:              'report error

Source File: C:\Documents and Settings\amir\My Documents\Visual Studio 2005\WebSites\YSTR\Default4.aspx    Line: 4

djsoltanAuthor Commented:
thanks alot, it works :d
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.