2

I have 2 dropdown lists dl9 and dl10 as given below.
If I click yes from dl9 dl10 is made visible, else it is hidden.

Now I want to make selected value 'none' for dl10 when i click on 'no' and it's going to database; if yes only 'completed' and 'ongoing' must b made visible.

How can I do this?

<asp:DropDownList ID="DropDownList9" runat="server" Width="128px"  onchange="display()"  >
        <asp:ListItem Value="yes">Yes</asp:ListItem>
        <asp:ListItem Value="no">No</asp:ListItem>
    </asp:DropDownList>

<asp:DropDownList ID="DropDownList10" runat="server" Width="107px" TargetControlID="DropDownList9" >
        <asp:ListItem Value="completed">Completed</asp:ListItem>
        <asp:ListItem Value="ongoing">Ongoing</asp:ListItem>
        <asp:ListItem Selected="True" Value="none" Enabled="False">[SELECT]</asp:ListItem>
    </asp:DropDownList>

My Javascript to hide dl10 is:

<script type="text/javascript" language="javascript">
    function display()
     {
         if (document.getElementById('<%=DropDownList9.ClientID%>').value == "no") 
        {
            document.getElementById('d1').style.visibility = "hidden";
            document.getElementById('<%=DropDownList10.ClientID%>').style.visibility = "hidden";
            document.getElementById('<%=DropDownList10.ClientID%>').value = "none";
            //DropDownList10.SelectedValue = "none";   not wrkin
        }
        else {
            document.getElementById('<%=DropDownList10.ClientID%>').style.visibility = "visible";
            document.getElementById('d1').style.visibility = "visible";
        }
    }
 </script>

My problem here is: When I click 'no' and submit 'completed' is going into database....but i need 'none' to be entered...

1
  • I have cleaned out the slang, typing errors, and boldface in your question. Please write proper questions and leave out the emotion. Commented Sep 6, 2013 at 7:02

3 Answers 3

4

Enabled="False" property in the ListItem is creating problem.

<asp:ListItem Selected="True" Value="none" Enabled="False">[SELECT]</asp:ListItem>

I removed and checked, it is working fine.

[Update]

If you want to hide the option, then hide that while loading of page by javaScript. Write this code inside script tags and it will hide the option.

window.onload = function () {
     document.getElementById('<%=DropDownList10.ClientID%>').options[2].style.display = "none";
};

[/Update]

Sign up to request clarification or add additional context in comments.

8 Comments

ya i kno....but if i remove enable=False....[SELECT] option will also be displayed wen i click on yes....i don want it to b displayed
Please check my updated answer. Remove Enabled="false" and use the javaScript to hide the option.
Yes it is working fine at my end. Let me tell you what you need to do. 1. Remove Enabled false property. 2. Add that window onload javaScript. You can check that in rendered html, one display "none" is added to that option.
well i placed that code in my else part of display() func.....got partial output....i tink now Selected="True" is creating problem
ya i removed it...next?
|
1

You have to add an element with value none

1 Comment

i hav added an element with value none....bit its not enabled becoz wen i click yes tat non value shud not be visible so... <asp:ListItem Selected="True" Value="none" Enabled="False">[SELECT]</asp:ListItem>
0
document.getElementById('<%=DropDownList10.ClientID%>').val("none").attr("selected", "selected");

1 Comment

not working.....i think first 'none' value must b enabled....i hav given enable=false.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.