我在1.aspx中有一个DropDownList控件邦定了数据库
当我点击1.aspx中的一个button时,弹出一个窗口(2.aspx),我添加信息,然后关闭该窗口(2.aspx),就可以在1.aspx中的DropDownList 中得到我添加的信息。谢谢帮忙!!

解决方案 »

  1.   

    关闭子窗口的同时刷新父窗口Response.Write("<script>alert('添加成功!');opener.location.href=opener.location.href;close();</script>");刷新爷爷窗口window.opener.opener.location.href='a.aspx'
      

  2.   

    用模态窗口,可以有一个返回值,将这个返回值添加进DropDownList中就可以了
      

  3.   

    function Goto(strUrl){
       str=window.showModalDialog(strUrl,'','dialogheight :300px; dialogwidth :700px; edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll:No;');
       //alert(str)
       if(str =='0')
       {
         // alert('操作失败');
          return false;
       }
       else if(str=='1')
       {
         // alert('操作成功');
        //  document.all.btnRef.focus();
          //alert('focus');
          document.all.btnRef.click();
          //alert('click');
          return false;
       }
    }
      

  4.   

    刷新父窗口的时候重绑一下
    DropDownList 的数据源
      

  5.   

    btnRef是一个width=0的按钮,你可以在这个单击事件里面把添加的东西insert进去
      

  6.   

    time_is_life(今夜太冷)的方法可能会造成服务器端不能得到绑定的值,因为在从数据库对DropDownList进行绑定的时候,没有新增加的项。如果要使用,可能需要一些辅助的控件,比如隐藏域呀什么的。
    简单一点,重新绑定。
      

  7.   

    这个倒不一定要刷新主页面,完全用javascript实现也可以
    <script language="javascript">
    function returnInput()
    {
    var tmp = document.getElementById("TextBox1").value;
    var oOption = opener.window.document.createElement("OPTION");
    oOption.innerText = tmp;
    oOption.value = tmp;
    var ddlst = opener.window.document.getElementById("DropDownList1");
    ddlst.options.add(oOption);
    window.opener = null;
    window.close();
    }
    </script>
    <INPUT onclick="returnInput();" style="Z-INDEX: 107; LEFT: 416px; POSITION: absolute; TOP: 152px"
    type="button" value="Button" id="Button2" name="Button2">
      

  8.   

    这个倒不一定要刷新主页面,完全用javascript实现也可以
    <script language="javascript">
    function returnInput()
    {
    var tmp = document.getElementById("TextBox1").value;
    var oOption = opener.window.document.createElement("OPTION");
    oOption.innerText = tmp;
    oOption.value = tmp;
    var ddlst = opener.window.document.getElementById("DropDownList1");
    ddlst.options.add(oOption);
    window.opener = null;
    window.close();
    }
    </script>
    <INPUT onclick="returnInput();" style="Z-INDEX: 107; LEFT: 416px; POSITION: absolute; TOP: 152px"
    type="button" value="Button" id="Button2" name="Button2">
      

  9.   

    To:Tom_Real() 
    我是想重新绑定
    我怎么在2.aspx中调用1.aspx中的DropDownList控件阿?我曾试着把DropDownList设置为public
    在2.aspx中声明一个1.aspx类的实例a,用a.DropDownList.dataSource=ds;但是出错!
    应该怎么写啊???
      

  10.   

    To:fphuang(人在哈尔滨) 
    你的方法很好,但在出现“添加成功”时后面页面变白能不能让他保持原态阿!
    还有opener.location.href=opener.location.href;这句是什么意思啊?
      

  11.   

    这就是关闭子窗口的同时刷新父窗口,就进行了数据绑定。Response.Write("<script>alert('添加成功!');opener.location.href=opener.location.href;close();</script>");都说得对。
      

  12.   

    用window.showModalDialog打开2.aspx,关闭后再返回服务器执行Button事情并在事件中重新绑定
      

  13.   

    这里是asp.net论坛耶,怎么一个个都喜欢全用javascript解决啊?
    在弹出页面的添加按钮下加个Session存储当前添加的值,而主页面则在Page_Load事件中加个
    if(Session[xxx]!=null)
    {
    把Session中的信息加入到DDL中的代码;
    }
    OK了;
      

  14.   

    哦,忘了,加完之后,记得释放该Session;
      

  15.   

    ASP。NET程式做得完美,少了Script是不可能的
      

  16.   

    这个当然,可事事用Script就不能了,就像这里,纯用javaScript,只不过能让用户当时看着高兴罢了,实际上什么信息也没留下,并且,HTML页面应该用来写其它更有用的javaScript代码,而不能浪费在这种小事情上;就算是用JS文件,写太多javaScript代码也不是什么好事(javaScript实在是太透明了)。
      

  17.   

    To:Belice(天下无风) 
    我要的是关闭此窗口就可以在父窗口中查到我添加的信息,关闭该窗口后都不调主窗口的Page_load();如果能调就好了!
      

  18.   

    To:fphuang(人在哈尔滨) 
    你的方法很好,但在出现“添加成功”时后面页面变白能不能让他保持原态阿!
    还有opener.location.href=opener.location.href;这句是什么意思啊?
      

  19.   

    可以调用的,你只要在添加按钮后加个脚本添加就成了:
    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script LANGUAGE=JavaScript>window.opener.window.document.forms(0).submit(); window.close();</script> ");其实就是让父窗口刷新(提交)一次
      

  20.   

    你们总用opener他的作用是什么啊?window.opener.window.document.forms(0).submit();这个可以分解的说明一下吗?
      

  21.   

    ......
    window不用说了,opener指创建者,当前页面是从哪个页面弹出的就指哪个页面,后面的依次就是指opener的window的document的forms,执行提交方法.
    forms是页面中form的集合,第一个form,就是forms(0)了。
      

  22.   

    Response.Write("<script language=javascript>location.href='Mst_users_query.aspx?code="+Convert.ToInt64( Request.QueryString["code"] )+"';</script>");
      

  23.   

    To:Belice(天下无风)
    呵呵~~~~谢谢讲解!