[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Drop Down Validation

Posted on 2006-05-03
4
Medium Priority
?
223 Views
Last Modified: 2012-05-05
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>
-----------------------------
0
Comment
Question by:djsoltan
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 16598597
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
0
 

Author Comment

by:djsoltan
ID: 16598691
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

-----------
0
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 1000 total points
ID: 16598775
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
Else
   'query database and show results
End if
0
 

Author Comment

by:djsoltan
ID: 16598954
thanks alot, it works :d
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question