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:ListI tem>
<asp:ListItem>2</asp:ListI tem>
<asp:ListItem Selected="True">*</asp:Lis tItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" Width="123px">
<asp:ListItem>1</asp:ListI tem>
<asp:ListItem>2</asp:ListI tem>
<asp:ListItem Selected="True">*</asp:Lis tItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
</div>
</form>
</body>
</html>
-------------------------- ---
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:ListI
<asp:ListItem>2</asp:ListI
<asp:ListItem Selected="True">*</asp:Lis
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" Width="123px">
<asp:ListItem>1</asp:ListI
<asp:ListItem>2</asp:ListI
<asp:ListItem Selected="True">*</asp:Lis
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
</div>
</form>
</body>
</html>
--------------------------
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.SelectedValu e="*" and DropDownList2.SelectedValu e<>"*" OR
Line 5: DropDownList1.SelectedValu e<>"*" and DropDownList2.SelectedValu e="*" Then
Line 6: 'report error
Source File: C:\Documents and Settings\amir\My Documents\Visual Studio 2005\WebSites\YSTR\Default 4.aspx Line: 4
-----------
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.SelectedValu
Line 5: DropDownList1.SelectedValu
Line 6: 'report error
Source File: C:\Documents and Settings\amir\My Documents\Visual Studio 2005\WebSites\YSTR\Default
-----------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks alot, it works :d
then in Button1_Click event:
If DropDownList1.SelectedValu
DropDownList1.SelectedValu
'report error
Else
'query database and show results
End if