在dropdownlist的SelectedIndexChanged事件里从数据库里取值到textbox里,但textbox里的值始终是第一次查询的结果,刷新也不行,怎么办?高手指点。THX

解决方案 »

  1.   

    if(!Page.IsPostBack){
    把page_load()里的代码写到这里
    }
      

  2.   

    dropdownlist的AutoPostBack=true在 SelectedIndexChanged  事件中写上:  
    //..........
    // textbox1.text = dropdownlist1.SelectedValue
      

  3.   

    先dropdownlist的AutoPostBack=true
    private void DropDownList1_electedIndexChanged(object sender, System.EventArgs e){
       TextBox1.Text = DropDownList1.SelectedItem.Text;
    或 TextBox1.Text = DropDownList1.SelectedItem.Value;
    }
      

  4.   

    是在这样实现的。LOAD 写入XML文件
    在前台调用
    <script language="vbscript">
    dim Mydom
    set Mydom=CreateObject("Msxml2.DOMDocument")
    Mydom.async=false
    mydom.setProperty "SelectionLanguage", "XPath"
    dim selDom
    sub loadunits()
    'Mydom.load("../Xml/CellResult.xml")
    Mydom.load("../web/Xml/CellResult.xml")
    end sub function selvalue1(str1)  

    if trim(str1)<>"" then             
    set selDom=Mydom.documentElement.selectNodes("/NewDataSet/Table[SpotCheck_Id="+trim(str1)+"]")
    for n=0 to selDom.length-1
    set secend=selDom.item(n).childNodes                   
    set oOption = document.createElement("OPTION")
    oOption.text=secend.item(1).text
    oOption.value=secend.item(0).text
    mainlayer.selSpot.options.add(oOption)
    next
    end if
    end function

    </script>
    <script language="javascript">
               
    function ClearSel()
    {    
    var i,mStr,Inp;
                       
    for (i=mainlayer.selSpot.length;i>=0;i--)
    {
    mainlayer.selSpot.remove(i);

                
    }
    //var oOption = document.createElement('OPTION');
    //oOption.text = "";
    //oOption.value = "";
    //mainlayer.SelSpot.options.add(oOption);
    }
     function show_target(obj){
                      (obj).style.visibility='visible';
                      (obj).style.zIndex=10;
                      (obj).style.left=event.clientX+document.body.scrollLeft;
                      (obj).style.top=event.clientY+document.body.scrollTop;
                       }
    </script>
      

  5.   

    <select id="selName"   onclick="selvalue1(mainlayer.selName.value)" style="LEFT: 16px; VISIBILITY: hidden; POSITION: absolute; TOP: 16px"
    onchange="javascript:ClearSel();mainlayer.Order.value=this.options[selectedIndex].text;" size="1" name="selName" runat="server" onblur ="javascript:if(this.options[selectedIndex].text==''){mainlayer.GFQM.text='';}">
    </select>
    <select id="selSpot" size="1" name="selSpot" runat="server" style="LEFT: 168px; VISIBILITY: hidden; POSITION: absolute; TOP: 16px"
    onClick="javascript:if(mainlayer.selSpot.options.length>0){mainlayer.GFQM.value=this.options[selectedIndex].text;}else {alert('请先选择机型!');}">
    </select>
    <input id="Order" name="Order" readOnly type="text" runat="server" class="noborder"
    onblur="javascript:mainlayer.selName.style.visibility='hidden';if(mainlayer.Order.value==''){mainlayer.selSpot.style.visibility='hidden';}" size=10 onfocus="javascript:mainlayer.GFQM.value='';show_target(mainlayer.selName);">
    <input id="GFQM"  readonly  name="GFQM" runat="server" onfocus="javascript:show_target(mainlayer.selSpot);"  onblur ="javascript:mainlayer.selSpot.style.visibility='hidden';">
      

  6.   

    Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
            Select Case Me.DropDownList1.SelectedValue
                Case "1"
                    Me.TextBox1.Text = 11
                Case "2"
                    Me.TextBox1.Text = 22
                Case "3"
                    Me.TextBox1.Text = 33        End Select
        End Sub
    <asp:DropDownList id="DropDownList1" style="Z-INDEX: 107; LEFT: 320px; POSITION: absolute; TOP: 200px"
    runat="server" AutoPostBack="True"></asp:DropDownList>