Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my aspx code
ASP.NET
<table>
        <tr>
            <td>Type</td>
            <td>
                <asp:DropDownList ID="typeDDL" runat="server" AutoPostBack="true">
                    <asp:ListItem Text="Please select" Value="" Selected="True"></asp:ListItem>
                    <asp:ListItem Text="Electricity" Value="Electricity"></asp:ListItem>
                    <asp:ListItem Text="Gas" Value="Gas"></asp:ListItem>


                </asp:DropDownList></td>
        </tr>
        <tr  runat="server" visible="false" id="mmbtu_convtr">
            <td>MMBTU_CONV</td>
            <td>
                <input type="text" runat="server" id="mmbtu_conv" name="mmbtu_conv" value="" style="width: 250px" /></td>
        </tr>
</table>


my c#
protected void Page_Load(object sender, EventArgs e)
        {
            if (typeDDL.SelectedValue == "gas")
            {
                mmbtu_convtr.Visible = true;
                pkstr.Visible = true;
            }
            else
            {
                mmbtu_convtr.Visible = false;
                pkstr.Visible = false;

            }
        }


What I have tried:

supposed it will work ,but when i select gas when tr mmbtu_convtr wont show?
Posted
Updated 20-Jun-16 1:25am
Comments
Sergey Alexandrovich Kryukov 18-Jun-16 18:36pm    
Are you going to switch visibility back and forth? Then switch it on client side, never server side.

Do you want to set visibility just once, when you deliver the page initially? The server-side code is perfect; what's the problem?

—SA
KyLim0211 18-Jun-16 18:39pm    
tried using jquery not working too..

$(document).ready(function () {
$('#typeddl').change(function () {
if (this.value == "Gas") {
$('#mmbtu_convtr').show();
$('#pkstr').show();
} else {
$('#mmbtu_convtr').hide();
$('#pkstr').hide();
}

});
});
Abdul Samad KP 19-Jun-16 7:32am    
In the dropdown 'G' is capital letter <asp:ListItem Text="Gas" Value="Gas">
and you are comparing it with "gas", which will never return true

1 solution

Like Abdul already mentioned, your comparison has the wrong casing ("gas" vs "Gas")..

Then it should work ok.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900