Tuesday, 17 May 2011

How to refer to Html select list from code behind

aspx:
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script type="text/javascript"> 
        function PopulateTextBox() { 
            var inner = document.getElementById("dropdownlist").value; 
            document.getElementById("hidden").value = inner; 
        } 
    </script> 
</head> 
 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    <select id="dropdownlist” name="cars" onchange="PopulateTextBox();"> 
    <option  value="volvo">Volvo</option> 
    <option value="saab">Saab</option> 
    <option value="fiat">Fiat</option> 
    <option value="audi">Audi</option> 
    </select> 
 
    </div> 
    <input id="hidden" runat="server" type="hidden" /> 
    <asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" /> 
    </form> 
</body> 
</html>
aspx.cs:
protected void Button1_Click(object sender, EventArgs e) 
    { 
        string car = hidden.Value; 
        //store the car into database 
    }

No comments:

Post a Comment