<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RefTopicList.aspx.cs" Inherits="Project.RefTopicList" %> <!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>
<base target="_self" />
<script src="../jquery/jquery-1.8.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
function Change(SCHeckBox, curHidOID) {
var objs = document.getElementsByTagName("input");
for (var i = ; i < objs.length; i++) {
if (objs[i].type.toLowerCase() == "checkbox")
objs[i].checked = false;
}
var SelectCheckBoxID = SCHeckBox.id;
document.getElementById(SelectCheckBoxID).checked = true;
$("#hidenOIDValue").val(curHidOID); }
function GetHidValue() { if ($("#hidenOIDValue").val() != "") {
returnValue = $("#hidenOIDValue").val();
window.close();
}
else {
alert('至少选择一项');
} }
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table border="" cellspacing="" cellpadding="">
<tr>
<td class="tb_td_content">
<asp:Button ID="QueryWatch" runat="server" Text=" 查 询 " OnClick="QueryWatch_Click" />
<input id="btnSure" type="button" value=" 确 定 "
onclick="GetHidValue();" />
</td>
</tr>
</table>
</div>
<div id="DivGridview">
<asp:GridView ID="CtrlGrid" runat="server" Width="80%" AllowSorting="True" CellPadding=""
BorderWidth="1px" BorderStyle="Solid" AutoGenerateColumns="False" OnRowDataBound="CtrlGrid_RowDataBound"
PageSize="" Height="128px">
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:HiddenField runat="server" ID="hidenCheckOID" Value='<%#Eval("ID") %>' />
<asp:CheckBox runat="server" ID="chkSelect" />
</ItemTemplate>
<HeaderStyle Wrap="False" Width="60px" HorizontalAlign="Center" />
<ItemStyle Wrap="false" Width="60px" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="名称">
<ItemTemplate>
<asp:Label ID="lblTopicName" runat="server" Text='<%# Eval("NAME")%>'></asp:Label>
</ItemTemplate>
<HeaderStyle Wrap="false" Width="100px" HorizontalAlign="Center" />
<ItemStyle Wrap="false" Width="150px" HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:HiddenField ID="hidenOIDValue" runat="server" />
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditProjectInfo.aspx.cs" Inherits="EditProjectInfo" %> <!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 id="Head1" runat="server"> <title></title> <link href="../../Themes/Default/control.css" rel="stylesheet" type="text/css" /> <link href="../../Themes/Default/ui.css" rel="stylesheet" type="text/css" /> <script src="../../Scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script> <script src="../../Scripts/jquery/jquery-1.8.0.min.js" type="text/javascript"></script> <script src="../../Scripts/Validate/ControlValidate.js" type="text/javascript"></script> <link href="../../Themes/Default/controlvalidate.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(document).ready(function () { var typevalue=<%=base.GetParaValue("type") %>; //后台传值判断是添加还是编辑 //0代表是编辑,页面上的选择按钮隐藏 if (typevalue == "") { $("#btnSelect").hide(); } else{ //单击选择按钮弹出要选择的信息,选中之后在该页面获取该信息 $("#btnSelect").click(function () { var oidd = window.showModalDialog('RefTopicList.aspx',"", 'dialogWidth=900px;dialogHeight=650px;help=no;location=no;scroll=no;resizable=no'); if (oidd != undefined && oidd != "") { GetTopicJson(oidd); //调用处理程序的方法,用json解析获取数据 } }); } }); function GetTopicJson(oid) { $.ajax({ type: "post", url: "HandlerRefTipic.ashx?OID="+oid , dataType: "json", success: function (data) { $("#txtprojectName").val(data[].TOPIC_NAME); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); } }); } </script> </head> <body> <form id="form1" runat="server"> <div class="datagrid_search_div">
<table class="tb" border="" cellpadding="" cellspacing="">
<tr>
<td class="tb_td_title">
项目名称:
</td>
<td class="tb_td_content" colspan="" valign="top">
<asp:TextBox ID="txtprojectName" runat="server" Width="500px" request="true"
MaxLength="" CssClass="txtbox" ToolTip="项目名称,最多100个字符!"></asp:TextBox>
<input id="btnSelect" type="button" value=" 选 择 " class="btn_long" />
</td>
</tr> <tr>
<td colspan="" class="tb_td_content" style="text-align: center;">
<asp:Button ID="btnSave" runat="server" class="btn_long" Text=" 保 存 "
OnClick="btnSave_Click" />
<input id="btnReset" type="button" value=" 重 置 " class="btn_long"
runat="server" onclick="javascript:document.forms[0].reset();" />
<asp:Label ID="TipInfo" runat="server" ForeColor="Red" Font-Bold="True"></asp:Label>
</td>
</tr>
</table>
</div> </body>
</html>
页面前台
<%@ WebHandler Language="C#" Class="HandlerRefTipic" %> using System;
using System.Web;
public class HandlerRefTipic : IHttpHandler { public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/Json";
context.Response.Clear();
context.Response.Write(GetTopicToJson(context.Request["OID"]));
context.Response.Flush();
context.Response.End(); }
/// <summary>
/// 根据标识得到课题对象实体转换成json格式输出
/// </summary>
/// <param name="oid"></param>
/// <returns></returns>
public string GetTopicToJson(string oid)
{
if(string.IsNullOrEmpty(oid))
{
return "";
}
TopicInfoObj obj = new TopicInfoRepository().GetTopicInfoObj(oid);
string str=new ConvertToJson().EntityToJson(obj);
return str; }
public bool IsReusable {
get {
return false;
}
} }
json解析获取数据
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PageGridBind(); }
}
protected void CtrlGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
HiddenField hidenCheckID = (HiddenField)e.Row.FindControl("hidenCheckOID");
CheckBox checkBox = e.Row.FindControl("chkSelect") as CheckBox;
checkBox.Attributes.Add("onclick", "Change(" + checkBox.ClientID + ",'" + hidenCheckID.Value + "')");
base.ChangeRowColor(e);
}
catch (Exception ex)
{ throw ex;
}
}
protected void PageGridBind()
{
GridView view = (GridView)this.FindControl("CtrlGrid");
if (view != null)
{
//DataTable dt=huoqushuju();
view.DataSource = dt;
view.DataBind();
}
}
}
最上面的页面后台代码
上面的js有的是我自己的样式文件,没有上传还有日历js都没有,大概就是这个思路,在第一个页面点击按钮然后弹出框,选中gridview中checkbox的,只能选择一行数据,获取到这行数据的id然后把这行数据通过json解析,然后再传到父级页面,给父级页面的控件赋值,就是这样一个思路,可以评论,吐槽,多多指正,谢谢!