none
Retaining the size of Drop Down List RRS feed

  • Question

  • I have 2 drop down lists. When i select 1st value from the 1st ddl, the 2nd ddl gets disabled. When i select 2nd value from 1st ddl, the 2nd ddl enables. This just what I needed. But there is a problem. When the 2nd ddl gets disabled, its size increases automatically & I don't want that. T have used table, update panel, trigger, content panel, still its not working. 
    I am attaching the portion of the code. Kindly help.

    <td>
    <label>Activity&nbsp;</label>
    </td>
    <td>
    <asp:UpdatePanel ID="Update_Panel1" runat="server">
    <ContentTemplate>
    <asp:DropDownList ID="ddl_Activity1" runat="server" AutoPostBack="True" 
    class="w100" onselectedindexchanged="ddl_Activity1_SelectedIndexChanged">     
    <asp:ListItem Text="Create Permanent Water Holes" Value="1"></asp:ListItem>
    <asp:ListItem Text="Improve Water Storage" Value="2"></asp:ListItem>
    </asp:DropDownList>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddl_SubActivity1" EventName="SelectedIndexChanged"/>
    </Triggers>
    </asp:UpdatePanel>
    </td>
    <td>
    <asp:label ID="lbl_SubActivity1" runat="server">Sub&nbsp;Activity</asp:label>
    </td>
    <td>
    <asp:UpdatePanel ID="Update_Panel2" runat="server">
    <ContentTemplate>
    <asp:DropDownList ID="ddl_SubActivity1" runat="server" 
    class="w100" AutoPostBack="True">
    <asp:ListItem Text="Desilting" Value="1"></asp:ListItem>
    <asp:ListItem Text="Deepening" Value="2"></asp:ListItem>
    <asp:ListItem Text="Repairing" Value="3"></asp:ListItem>
    </asp:DropDownList>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="ddl_SubActivity1" EventName="SelectedIndexChanged"/>
    </Triggers>
    </asp:UpdatePanel>    
    </td>
    Friday, January 24, 2014 1:08 PM

Answers

  • Hi, Debranjan.

    I saw from one of your other posts that you would like the second drop down list to disappear if they select the second option in the first drop down list. THen you'd like it to reappear if they choose the first option again.

    In your click event handler in the *.aspx.cs code, just change the second drop down list's visible property to either true or false. Like this:

    
    
    protected void ddl_Activity1_SelectedIndexChanged(object sender, EventArgs e)
    {
      ddl_SubActivity1.Visible = !ddl_SubActivity1.Visible;
    }

    If you add more options to the drop down lists with more rules, then you will will next to add if/else blocks to the code.

    This is the Microsoft certification and Learning forum.

    This question would best be answered on the ASP.NET Web Forms forum, located here:
    http://forums.asp.net/18.aspx/1?Web+Forms

    Good luck!


    Best wishes, Davin Mickelson

    Friday, January 24, 2014 2:44 PM
    Answerer