Link to home
Start Free TrialLog in
Avatar of djsoltan
djsoltan

asked on

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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="123px">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem Selected="True">*</asp:ListItem>
        </asp:DropDownList>
        &nbsp;
        <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" Width="123px">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem Selected="True">*</asp:ListItem>
        </asp:DropDownList>&nbsp;
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
        </div>
    </form>
</body>
</html>
-----------------------------
Avatar of Ramuncikas
Ramuncikas
Flag of Lithuania image

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
Else
   'query database and show results
End if
Avatar of djsoltan
djsoltan

ASKER

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

-----------
ASKER CERTIFIED SOLUTION
Avatar of Ramuncikas
Ramuncikas
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks alot, it works :d