selection in one ddl field makes another ddl as a required field.

I have to accomplish two scenarios:

1. I have two dropdownlist fields say A and B

and A has options as 'xx','aa','bb','yy','ss'

A is a required field, if user selects 'xx' or 'yy' from the dropdownlist A then I need to make B as a required field.

 2. There is a datefield which is not required field. I need to let user enter 'N/A' in this field if they do not have any relevant date , the way i was trying to accomplish this task is :

provide a checkbox in front of this date field, if user checks it  I will fill it with 'N/A'

 

Please provide any direction,link or suggestion how to accomplish the above two scenarios.

Thanks.

0
gridview
1/25/2009 6:43:58 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
525 Views

Similar Articles

[PageSpeed] 54

Just to be clear, although you have probably already figured this out, the built in validators do not directly support these scenarios.

You could use a custom validator control which depending on conditions sets other custom validator controls .Enabled to true or false.

Or you could create your own custom validator from the ground up thats based off something like this:

0
rtpHarry
1/25/2009 4:22:18 PM

 

gridview:

I have to accomplish two scenarios:

1. I have two dropdownlist fields say A and B

and A has options as 'xx','aa','bb','yy','ss'

A is a required field, if user selects 'xx' or 'yy' from the dropdownlist A then I need to make B as a required field.

 2. There is a datefield which is not required field. I need to let user enter 'N/A' in this field if they do not have any relevant date , the way i was trying to accomplish this task is :

provide a checkbox in front of this date field, if user checks it  I will fill it with 'N/A'

 

Please provide any direction,link or suggestion how to accomplish the above two scenarios.

Thanks.

Based on my experience, I suggest you resolve it by using JavaScript. Please refer to the following code:

 

<html  >
<head id="Head1" runat="server">
    <title>CustomValidator Example</title>
    <script type="text/javascript">
    function CheckDte(obj)
    {
      if(obj.checked)
      {
         document.getElementById("TextBox1").value="N/A";
      }
      else
      {
         document.getElementById("TextBox1").value="";
      }
    }
    function CheckDropDownList()
    {
       var drop = document.getElementById("DropDownList1")
       var drop2 = document.getElementById("DropDownList2")
       if(drop.options[0].selected||drop.options[2].selected)
       {
          if(drop2.options[0].selected)
          {
            alert('Please ensure you have selected item in DropDownList2')
            return false;
          }
          else
          {
             return true;
          }
       }
       return true;
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem>A</asp:ListItem>
        <asp:ListItem>B</asp:ListItem>
        <asp:ListItem>C</asp:ListItem>
        <asp:ListItem>D</asp:ListItem>
    </asp:DropDownList>
    <asp:DropDownList ID="DropDownList2" runat="server">
     <asp:ListItem>Please Select</asp:ListItem>
        <asp:ListItem>E</asp:ListItem>
        <asp:ListItem>F</asp:ListItem>
        <asp:ListItem>G</asp:ListItem>
        <asp:ListItem>H</asp:ListItem>
    </asp:DropDownList>
    <br />
    <asp:CheckBox ID="CheckBox1" runat="server" onclick="CheckDte(this)"/>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return CheckDropDownList()"/>
    
    </form>
    
      
</body>
</html>
  

Gary yang - MSFT
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Gary
1/29/2009 3:36:19 AM
Reply: