类似于 招聘网上的那种 点击一个按钮 然后弹出一个小窗口 这个小窗口中有很多的复选框 可以多选【要求复选框所绑定的值 是动态的(数据库中取的值) 不是固定多少个的那种】
选择确定后 把值返回与 主页面显示 这个一般怎么实现求解!!
选择确定后 把值返回与 主页面显示 这个一般怎么实现求解!!
解决方案 »
- asp.net做一个修改密码的模态对话框的问题
- 导出EXCEL时,可否控制EXCEL视图的显示比例?
- 关于string转换成ValidationDataType的方法
- AutoComplete,请大家帮我看下这个简单例子,怎么没有反应。
- 我想实现下面这样一个需求,具体实现请大家给个思路。
- excel文件直接在浏览器内显示的问题
- 有人知道中企动力这公司用的建站系统是什么系统吗?
- .NET网站 用COOKIE做身份验证问题!
- 如何保护用户上传的附件,只有通过程序才能访问。急!!!!!!!!!!!
- 紧急求助:不能保存cookie
- 求救!asp.net中,list怎样绑定数据库里的一个表。
- MVC 3 一般怎么做前台会员登录验证?
最最实用的是用AJAX,读取某个服务或程序,例如.ashx或者.asmx,然后后台程序给到前台,前台再用JS将复选框显示到html中,并弹出弹出框。当然咯,其实ASP.NET中还有别的方法,虽然原理一样,但是实现起来不一样。例如:在页面中加入updatepanel,当点击按钮后,按钮引起后台事件,后台事件中为前台事先植入的某个div写入html,或者动态添加复选框,然后写一个JS弹出这个div,最后用scriptmanager将该JS植入程序最后。于是用户点击按钮后,页面未刷新,但是弹出了一个框,里面有动态的复选框。当然,还可以完全脱离后台,纯前台实现,只不过是事先将可能要弹出框的内容或数据隐藏在html中。万变不离其宗,反正弹出必须是JS,至于弹出框中的复选框(无非就是数据),要么事先,要么事后。
我没说明白么???
你上下 智联招聘 那种网站 就能看到效果!
我就想来个简单的 点击一个按钮 弹出一个多项选择 的窗口 然后将选择的值返回 其中多项选择的值是从数据库中绑定的 不是固定的那种
Webform1.aspx<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<div align="center">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" runat="server" Font-Bold="true">
从当前页面打开新窗口,并把变量传递到新窗口的例子,可以多次打开提交。
</asp:label><br>
<br>
<asp:textbox id="TextBox1" runat="server" Width="600px">这是初始值,将被传递到新窗口。</asp:textbox><br>
<br>
<asp:button id="Button1" runat="server" Width="96px" Text="打开窗口2"></asp:button>
<asp:button id="Button2" runat="server" Width="96px" Text="打开窗口4"></asp:button></form>
</div>
</body>
</HTML>
Webform1.aspx.csusing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ShowModalTest
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
// 在此处放置用户代码以初始化页面
string strScript= "\n";
if (!IsClientScriptBlockRegistered("clientScript"))
{
strScript = "<script>\n";
strScript += "function OpenWin(){\n";
strScript += "var str=window.showModalDialog('WebForm2.aspx',document.Form1.TextBox1.value,'help:no')\n";
strScript += "if(str!=null) document.Form1.TextBox1.value=str\n";
strScript += "}\n";
strScript += "</script>\n";
RegisterClientScriptBlock("clientScript", strScript);
}
if (!IsClientScriptBlockRegistered("clientScript2"))
{
strScript = "<script>\n";
strScript += "function OpenWin2(){\n";
strScript += "var str=window.showModalDialog('WebForm4.aspx',document.Form1.TextBox1.value,'help:no')\n";
strScript += "if(str!=null) document.Form1.TextBox1.value=str\n";
strScript += "}\n";
strScript += "</script>\n";
RegisterClientScriptBlock("clientScript2", strScript);
}
Button1.Attributes.Add("onclick", "OpenWin()");
Button2.Attributes.Add("onclick", "OpenWin2()"); } #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
Webform2.aspx <%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE>WebForm2</TITLE>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<frameset rows="0,*">
<frame src="about:blank">
<frame src="WebForm3.aspx">
</frameset>
</HTML>
WebForm3.aspx<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm3</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout" id="MyBody" runat="server">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" runat="server">请输入您的大名:</asp:Label><br>
<br>
<asp:TextBox id="TextBox1" runat="server" Width="320px"></asp:TextBox><br>
<br>
<asp:Button id="Button1" runat="server" Text=" 提 交 "></asp:Button>
</form>
</body>
</HTML>
WebForm3.aspx.csusing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace ShowModalTest
{
/// <summary>
/// WebForm3 的摘要说明。
/// </summary>
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlControl MyBody;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(IsPostBack)
{
string strScript = "<script>\n";
strScript += "window.parent.returnValue='" + TextBox1.Text.Replace("'", "\'") + "'\n";
strScript += "window.parent.close()\n";
strScript += "</script>\n";
if (!IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", strScript);
}
else
{
MyBody.Attributes.Add("onload", "document.Form1.TextBox1.value=window.parent.dialogArguments");
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
Webform4.aspx<%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm4" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm4</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<iframe frameborder="no" src='WebForm3.aspx' style="WIDTH: 368px; HEIGHT: 192px"></iframe>
</form>
</body>
</HTML>
1.用checkboxlist控件
2.循环赋值
http://www.cnblogs.com/insus/archive/2012/09/13/2682766.html
我现在 弹出的代码已经写好了 动态生成CheckBox的 也写好了
现在就差 点击确定 将选中的CheckBox的text 赋值给 父页面的文本框子页面动态生成checkbox
DataTable dt = UserBll.SelUser("Sys_User");
CheckBox ckb = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
ckb = new CheckBox();
ckb.ID = string.Format("chk{0}", i.ToString());
ckb.Text = string.Format(dt.Rows[i][2].ToString(), i);
ckb.CheckedChanged += new EventHandler(ckb_CheckedChanged);
//ckb.Location = new Point(0, i * 20);
ckb.Checked = false;
Page.Form.Controls.Add(ckb); }
这些都没问题了
然后怎么点击确定按钮 将选择的值 依次传回父页面 并赋值给父页面的文本框?
<script language="javascript" type="text/javascript">
function openReasonWin()
{
//新窗口的文档名称
var srcFile = "SelUserName.aspx";
//高度,位置等
var winFeatures = "dialogHeight:550px; dialogLeft:300px;";
//把输入页面的reason input传给弹出窗口
var obj = document.getElementById("Button2");
//将input作为对象传递给新窗口
//ok,open new windows
/*
设置传给子窗口的值
obj.value="要传递的值";
*/
window.showModalDialog(srcFile, obj, winFeatures);
}
</script>
<form id="Form" name="Form" action="" runat="server">
<input id="txt_Cyr" name="txt_Cyr" type="text" />
<input id="Button2" type="button" class="button" onclick="openReasonWin()" value="弹出" />子画面
function aa() {
var objs = document.getElementsByTagName("input"); //拼凑的字符串
var str = ''; //遍历
for (var i = 0; i < objs.length; i++) {//遍历所有的,被选中的复选框
if (objs[i].type.toLowerCase() == "checkbox" && objs[i].checked)
//连接客串
strstr = str + objs[i].value + ',';
}
window.opener.document.Form.txt_Cyr.value = str;
window.close();
}<input id="Button1" type="button" onclick="aa()" value="提交" />
当我点击提交的时候 弹出无法获取属性document的值,对象为空的网页错误