当DropDownList中的值变化时,<asp:TextBox ID="txtname" runat="server"></asp:TextBox> 
文本框txtname的值也跟着变化.
但是问题是,不能启用AutoPostBack,因为会刷新掉别的文本框的值.
想到用js实现可能是最好的方式,但是不知道怎么写,希望有高手指点,必留代码啊...!

解决方案 »

  1.   

    因为其他文本框的值是从当前页面计算得到的,如果这里启用AutoPostBack,就会出现刷新的情况,页面会重新loading,其他文本框的值会返回到一开始时的默认状态和默认值.
    希望有高手指点,主要是不用AutoPostBack能实现的办法
      

  2.   

    把DropDownList的OnSelectedIndexChanged写近JS,然后在JS里面获得txtname的引用,修改其值就行了
      

  3.   

    js:
            function MySelect()
            {   
                var ddl = document.getElementById("DropDownList1");
                var avalue=ddl.options[ddl.selectedIndex].value ;
                document.getElementById("TextBox1").value=avalue;
            }c#,在page_Load中
       DropDownList1.Attributes.Add("onchange", "MySelect()");
      

  4.   

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>DropDownList与TextBox关联</title>
        <script type="text/javascript" language="javascript">
        function ddlchange()
        {
            var ddl=document.getElementById("<%=ddl01.ClientID %>");
            var tb=document.getElementById("<%=txtname.ClientID %>");
            tb.value=ddl.value;
        }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="lbl01" runat="server" Text="请选择你所在城市" />
            <asp:DropDownList ID="ddl01" runat="server" onchange="ddlchange()">
               <asp:ListItem>北京</asp:ListItem>
               <asp:ListItem>上海</asp:ListItem>
               <asp:ListItem>成都</asp:ListItem>
               <asp:ListItem>天津</asp:ListItem>
            </asp:DropDownList>        
            <asp:TextBox ID="txtname" runat="server" />
        </div>
        </form>
    </body>
    </html>
      

  5.   

    我上面说错了OnSelectedIndexChanged这是服务器端事件,会刷新,必须使用客户端事件onchange.
      

  6.   


    这个简单,用AJAX 来做