C#页面弹出窗口+子窗口请求数据+子窗口点选操作+向父页面回传值
SON页
<html>
<head>
<title>计划选择</title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$.post("gervalue.ashx", { "action": "getpagedata", "pagenum": "1" }, function (data, status) {
var comments = $.parseJSON(data);
$("#ulComment").empty();
for (var i = 0; i < comments.length; i++) {
var comment = comments[i];
//var li = $("<li>" + comment.PostDate + ":" + comment.Msg + "</li>");
var item = "<li onclick='getevent(this)'>" + comment.Msg + "<input id='hid' type='hidden' value=" + comment.PostDate + "></li>"
$("#tul").append(item);
}
});
</script>
<script type="text/javascript">
function getevent(va) {
var tval = $(va).text(); //取到li里包涵的文本值
var ival = $(va).find("input").val(); //取得隐藏字段里的值
var value = $("#rul").children().eq(0).text(); //获取li里的值
var hehe = "";
var test = $("#rul").children().length;
for (var i = 0; i < test; i++) {
//var nva = $("#rul").children().eq(i).text();
var nva = $("#rul").children().eq(i).find("input").val();
if (ival == nva) {
alert('重复了');
hehe = "不得哦";
}
}
if (hehe == "") {
var item = "<li onclick='selectevent(this)'>" + tval + "<input id='hid' type='hidden' value=" + ival + "></li>"
$("#rul").append(item);
var test = $("#rul").children().length;
for (var i = 0; i < test; i++) {
var Name = $("#rul").children().eq(i).text();
var Id = $("#rul").children().eq(i).find("input").val();
var realvalue = realvalue + Id + "," + Name + ",";
postvalue(realvalue);
}
}
}
function selectevent(th) {
var value = $(th).remove(); //移除当前项
var test = $("#rul").children().length;
for (var i = 0; i < test; i++) {
var Name = $("#rul").children().eq(i).text();
var Id = $("#rul").children().eq(i).find("input").val();
var realvalue = realvalue + Id + "," + Name + ",";
postvalue(realvalue);
}
if (test == 0) {
var realvalue = "1";
postvalue(realvalue);
}
}
function postvalue(vals) {
window.name = "cwindow"
dialogArguments.oInput.value = vals;
}
</script>
</head>
<body>
<div id="tdiv" style="width: 50%; height: 200px; overflow-y: scroll; border: 1px solid;">
<ul id="tul" style="cursor: pointer; list-style: none; width: 100%; background-color: Gray;">
</ul>
</div>
<div id="recive" style="width: 50%; height: 200px; overflow: scroll; border: 1px solid;">
<ul id="rul" style="cursor: pointer; list-style: none; width: 100%; background-color: Gray;">
</ul>
</div>
</body>
</html>
PARENT页
<!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>
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
function smdWin() {
win = window.showModelessDialog("JStree.htm", window, "dialogWidth=500px;dialogHeight=500px;status=0;scroll=no")
}
function valuechang() {
var value = $("#oInput").val();
var vaa = value.substring(9, value.length);
var lastva = vaa.split(",");
var Name = "";
var Id = "";
var values = $.map(lastva, function (value) {
var result = new Number(value);
if (value != "") {
isNaN(result) ? Name += value + "," : Id += result + ",";
}
});
$("#show").val(Name);
}
function immediately() {
var element = document.getElementByIdx_x("oInput");
if ("\v" == "v") {
element.onpropertychange = webChange;
} else {
element.addEventListener("input", webChange, false);
}
function webChange() {
if (element.value) { valuechang(); }
}
}
</script>
</head>
<body>
<input id="oInput" type="hidden" /><input id="show" type="text" />
<input type="button" onclick="smdWin()" value="打开子窗口" />
<script type="text/javascript">
immediately();
</script>
</body>
</html>
AJAX取数据页
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
namespace test
{
/// <summary>
/// gervalue 的摘要说明
/// </summary>
public class gervalue : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string pagenum = context.Request["pagenum"];
DataTable dt = getdata.GetMessage(pagenum);
List<Comment> list = new List<Comment>();
for (int i = 0; i < dt.Rows.Count;i++)
{
list.Add(new Comment() { PostDate = dt.Rows[i][0].ToString(), Msg = dt.Rows[i][1].ToString() });
}
JavaScriptSerializer jss = new JavaScriptSerializer();
context.Response.Write(jss.Serialize(list));
//context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
public class Comment
{
public string PostDate { get; set; }
public string Msg { get; set; }
}
}
MS-SQL数据库取数据页
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace test
{
public class getdata
{
public static DataTable GetMessage(string sql)
{
string Connect = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection sc = new SqlConnection(Connect);
sc.Open();
SqlCommand cm = new SqlCommand("select * from Plan_Work where PlanId<30");
cm.Connection = sc;
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(cm);
sda.Fill(ds, "huyonghong");
DataTable dt = ds.Tables["huyonghong"];
return dt;
}
}
}