以下语句可以将模式对话框'NewValue.aspx'的值str返回给主页面的TextBox1:
string strScript="<Script language='Javascript'>";
strScript += "var str=window.showModalDialog('NewValue.aspx');";
strScript += "if(str!=null)  {document.Form1.TextBox1.value=str}";
strScript += "</script>";this.Page.RegisterStartupScript("NewValue",strScript);--------------------------------------------------------------------
那么,要把值str返回给主页面的DropDownList1,即在DropDownList1中添加一项str,
并使DropDownList1的当前值为str,应该怎么做?谢谢!

解决方案 »

  1.   

    弹出的窗口加如下的JS代码
    var ret = new Array();
    ret[0] = 你的在DropDownList中显示的text";
    ret[1] = "你在DropDownList中显示的Value";
    window.returnValue = ret;然后在父窗口如下得到返回值
    var result = window.ShowModalDialog(..后面自己写
    在将返回值加入到dropdownlist中
    var drop = document.getElement('你的dropdownlist的id);
    var option = document.createElement('option');
    option.text = result[0];
    option.value = result[1];
    drop.add(option);
    完工。。
      

  2.   

    jonescheng(C#,呵呵我会一点) 的办法是可行的。不过,我记得window.returnValue = ret;
    应该是parent.window.returnValue = ret;
      

  3.   

    谢谢。
    我用的是window.parent.returnValue = ret;可以得到结果了。但是,1、每执行一次该段代码,上一次新增的值就没有了,而替以新值。为什么?
    2、新增的同时,希望同时选中该项,如何写?
      

  4.   

    var str=window.showModalDialog('NewValue.aspx');
    if(str!=null)
    {
              var list=document.Form1.DropDownList1;
             var option = document.createElement('option');
    option.text =str;
             option.value =str;
    list.add(option);
    list.selectIndex=list.options.length;--新增的同时,希望同时选中该项,此句怎写才对?
    }
      

  5.   

    自己搞定了
    list.selectedIndex=list.options.length-1;
    谢谢!