js 点击按钮弹出另一页,选择值后,返回到当前页(asp.net实例)

来源:互联网 发布:麟龙软件至尊版 编辑:程序博客网 时间:2024/06/06 03:07
1主页面代码:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test1.aspx.cs" Inherits="ClManageSys.Test1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>无标题页</title><script type="text/javascript">function GetInfo(openwindow) {var str = window.showModalDialog(openwindow, window, "dialogWidth=740px;dialogHeight=600px;center=yes;help=no;resizable=no;status=no");if (!str)return;document.getElementById("tb1").value=str[0];document.getElementById("tb2").value=str[1];}</script></head><body><form id="form1" runat="server"><div id="autosuggest" style="width:160px;font-size:12px;"><ul></ul></div><div> <br />    登陆名:<input id="tb1" runat="server" readonly="readonly"/> 真实姓名:<input id="tb2"        runat="server" readonly="readonly"/><input type="button" id="selectActive" runat="server" onclick="javascript:GetInfo('test.aspx')" value="..." /></div></form></body></html> 2弹出窗口页面<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="ClManageSys.test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>无标题页</title>    <script type="text/javascript" language="javascript">function dbclick_return_and_close(strid, strvalue) {var str = new Array(strid, strvalue);window.returnValue = str;window.close();}</script></head><body>    <form id="form1" runat="server">    <div>                 <br />        单击登陆名选择一条记录<asp:GridView ID="GridView1" runat="server" onpageindexchanging="r"            onrowdatabound="GridView1_RowDataBound" AutoGenerateColumns="False">            <Columns>                <asp:TemplateField HeaderText="登陆名">                    <ItemTemplate>                    <a href="#" onclick="javascript:dbclick_return_and_close( '<%#Eval("uname") %>', '<%#Eval("truename") %>');"><%#Eval("uname") %></a>                    </ItemTemplate>                </asp:TemplateField>                <asp:TemplateField HeaderText="真实姓名">                    <ItemTemplate>                        <%#Eval("truename") %>                    </ItemTemplate>                </asp:TemplateField>            </Columns>        </asp:GridView>        </div>    </form></body></html>3弹出窗口.cs代码:using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using Excel = Microsoft.Office.Interop.Excel;using System.Text;using System.IO;using System.Reflection;using System.Data.SqlClient;namespace ClManageSys{    public partial class test : System.Web.UI.Page    {        public static readonly string ConnectionString = ConfigurationSettings.AppSettings["StrCon"].ToString();       SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["StrCon"].ToString());        protected void Page_Load(object sender, EventArgs e)        {            test123();        }        public void test123()        {            SqlCommand cmd = new SqlCommand();            cmd.CommandText = "select * from Users";            cmd.Connection = con;            con.Open();            DataTable dt = new DataTable();            dt.Load(cmd.ExecuteReader());            GridView1.DataSource = dt;            GridView1.DataBind();            con.Close();                   }   }}


 

效果图