asp.net下用js实现弹出子窗口选定值并返回
对应上一篇博客代码:
父页面:
<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=9" >
<title></title>
<script type="text/javascript">
function test() {
//window.showModalDialog("test.aspx?tabname=book", window, 'dialogHeight=400px;dialogWidth=600px;');
window.showModalDialog("B.aspx", window, 'dialogHeight=400px;dialogWidth=600px;');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="跳转到B页面" OnClientClick="test();"/><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
框架法(fream包含gridview页面):
框架子页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=9" >
<title></title>
<script type="text/javascript">
function test() {
var child;
child = window.document.getElementById("child").contentWindow;
window.dialogArguments.document.getElementById("TextBox1").value = child.document.getElementById("tb_name").value;
window.close();
}
</script>
</head>
<frameset>
<frame id="child" src="CZB.aspx?tabname=<%=set_tabname()%>"></frame>
</frameset>
</html>
gridview页面:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=9" >
<title></title>
<script type="text/javascript">
function set() {
window.parent.test();
}
</script>
</head>
<body>
<form id="form1" runat="server" >
<div>
<asp:TextBox ID="tb_name" runat="server"></asp:TextBox>
<asp:Button ID="bt_in" runat="server" Text="搜索" onclick="bt_in_Click" />
<asp:Button ID="bt_re" runat="server" Text="重置" />
<asp:Button ID="Button1" runat="server" Text="确认选择" onclick="Button1_Click" />
<input id="Button2" type="button" value="回传" onclick="set();"/> <asp:GridView ID="gvSell" runat="server"
onpageindexchanging="GridView1_PageIndexChanging" PageSize="5" >
<Columns>
<asp:TemplateField HeaderText="数据选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PageButtonCount="5" PreviousPageText="上一页" />
<PagerStyle Font-Names="宋体" Font-Size="15px" />
</asp:GridView>
<div class="gridItem" style="padding: 5px; margin: 0px; border: 0; width: 40%; float: left; text-align: left; height: 20px; font-size: 15px;" aria-multiselectable="True"> 共有<span id="spanTotalInfor"></span>条记录 当前第<span id="spanPageNum"></span>页 共<span id="spanTotalPage"></span>页</div>
<div class="gridItem" style=" border-style: none; border-color: inherit; border-width: 0; padding: 5px; width: 225px; float: right; text-align: center; height: 20px; vertical-align: middle; font-size: 15px;"> <span id="spanFirst" ><img src='img/first.png'/></span> <span id="spanPre"><img src='img/back.png'/></span><span id="spanInput" style="margin: 0px; padding: 0px 0px 4px 0px; height:100%; "> 第<input id="Text1" type="text" class="TextBox" onkeyup="x()" style="height:20px; text-align: center" />页 </span><span id="spanNext"><img src='img/front.png'/></span> <span id="spanLast"><img src='img/last.png'/></span> </div>
</div> </form>
</body>
</html>
gridview后台页面:
public partial class CZB : System.Web.UI.Page
{
string str = WebConfigurationManager.ConnectionStrings["TempleConnectionString"].ConnectionString; protected void databind(string sql)
{
using (SqlConnection conn = new SqlConnection(str))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{ cmd.CommandText = sql;
SqlDataAdapter ap = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ap.Fill(ds);
gvSell.DataSource = ds.Tables[];
gvSell.DataBind();
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
databind("select * from book");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string strs="";
for (int i = ; i <= gvSell.Rows.Count - ; i++)
{
CheckBox cbox = (CheckBox)gvSell.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
strs = gvSell.Rows[i].Cells[].Text.ToString();
tb_name.Text = strs;
}
}
} protected string getvalue()
{
string str;
for (int i = ; i <= gvSell.Rows.Count - ; i++)
{
CheckBox cbox = (CheckBox)gvSell.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
return gvSell.Rows[i].Cells[].Text.ToString();
}
}
return "";
} protected void bt_in_Click(object sender, EventArgs e)
{
string sql = "select * from book where bookName like '%" + tb_name.Text + "%'";
databind(sql);
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvSell.PageIndex = e.NewPageIndex;
databind("select * from book");
}
}
js实现方法:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function getvalue() {
var table = document.getElementById("gvSell");
var s=0;
for(var i=1;i<table.rows.length;i++) {
var input = table.rows[i].cells[0].getElementsByTagName("input")[0].checked;
if (input == true)
{
window.dialogArguments.document.getElementById("TextBox1").value = table.rows[i].cells[3].innerHTML;
s = 1;
window.close();
}
}
if(s!=1)
alert("您未勾选任何一个选项!");
}
//搜索
function search() {
var content = document.getElementById(tb_name).value;
if (content == "") {
alert("您未输入任何内容!");
return;
}
var table = document.getElementById("gvSell");
var txt = document.getElementById("tb_name").value;
var arr = new Array();
var j = 0;var judge = 0;
//获取相关行数
for (var i = 1; i < table.rows.length; i++) {
if (table.rows[i].cells[3].innerHTML == txt || table.rows[i].cells[3].innerHTML.indexOf(txt) > -1)
{
arr[j] = i;
j++;
}
}
if (j == 0) {
alert("未找到有关数据!");
return;
}
//删除无关的行
for (i = i-1; i > 0; i--) {
judge=0;
for (var k = 0; k < j; k++)
if (arr[k] == i)
judge = 1;
if (judge == 0)
document.getElementById("gvSell").deleteRow(i); }
y();
} function delet() {
document.getElementById("tb_name").value = "";
}
</script> </head>
<body>
<form id="form1" runat="server">
<div>
<input id="tb_name" type="text" />
<input id="Button3" type="button" value="搜索" onclick="search();"/>
<input id="Button1" type="button" value="选择" onclick="getvalue();"/>
<input id="Button2" type="button" value="重置" onclick="delet();"/>
<input id="tb_hidden" type="text" style="visibility: hidden" />
<asp:GridView ID="gvSell" runat="server" >
<Columns>
<asp:TemplateField HeaderText="数据选择">
<ItemTemplate>
<input id="Checkbox2" type="checkbox" />
</ItemTemplate>
</asp:TemplateField>
</Columns> </asp:GridView>
<div class="gridItem" style="padding: 5px; margin: 0px; border: 0; width: 40%; float: left; text-align: left; height: 20px; font-size: 15px;" aria-multiselectable="True"> 共有<span id="spanTotalInfor"></span>条记录 当前第<span id="spanPageNum"></span>页 共<span id="spanTotalPage"></span>页</div>
<div class="gridItem" style=" border-style: none; border-color: inherit; border-width: 0; padding: 5px; width: 225px; float: right; text-align: center; height: 20px; vertical-align: middle; font-size: 15px;"> <span id="spanFirst" ><img src='img/first.png'/></span> <span id="spanPre"><img src='img/back.png'/></span><span id="spanInput" style="margin: 0px; padding: 0px 0px 4px 0px; height:100%; "> 第<input id="Text1" type="text" class="TextBox" onkeyup="x()" style="height:20px; text-align: center" />页 </span><span id="spanNext"><img src='img/front.png'/></span> <span id="spanLast"><img src='img/last.png'/></span>
</div>
</div>
<script type="text/javascript">
var theTable = document.getElementById("gvSell");
var txtValue = document.getElementById("Text1").value;
function y() {
theTable = document.getElementById("gvSell");
txtValue = document.getElementById("Text1").value;
renovate();
}
function x() {
var txtValue2 = document.getElementById("Text1").value;
if (txtValue != txtValue2) {
if (txtValue2 > pageCount()) { }
else if (txtValue2 <= 0) { }
else if (txtValue2 == 1) {
first(); }
else if (txtValue2 == pageCount()) {
last(); }
else {
hideTable();
page = txtValue2;
pageNum2.value = page; currentRow = pageSize * page;
maxRow = currentRow - pageSize;
if (currentRow > numberRowsInTable) currentRow = numberRowsInTable;
for (var i = maxRow; i < currentRow; i++) {
theTable.rows[i].style.display = '';
}
if (maxRow == 0) { preText(); firstText(); }
showPage();
nextLink();
lastLink();
preLink();
firstLink();
} txtValue = txtValue2;
}
}
function renovate() {
numberRowsInTable = theTable.rows.length - 1; //table值发生变化 更新分页
for (var i = pageSize + 1; i < numberRowsInTable + 1; i++) {
theTable.rows[i].style.display = 'none';
}
for (var j = 0; j <= 5; j++) {
if (j > numberRowsInTable)
break;
theTable.rows[j].style.display = '';
}
inforCount(); totalPage.innerHTML = pageCount();
showPage();
pageNum2.value = page; if (pageCount() > 1) {
nextLink();
lastLink();
}
}
</script>
<script type="text/javascript" src="Pagging.js"></script>
</form>
</body>
</html>
相关js代码:
var totalPage = document.getElementById("spanTotalPage");
var pageNum = document.getElementById("spanPageNum");
var totalInfor = document.getElementById("spanTotalInfor");
var pageNum2 = document.getElementById("Text1"); var spanPre = document.getElementById("spanPre");
var spanNext = document.getElementById("spanNext");
var spanFirst = document.getElementById("spanFirst");
var spanLast = document.getElementById("spanLast");
var pageSize = 5; var numberRowsInTable = theTable.rows.length-1; var page = 1;
//下一页
function next() { if (pageCount() <= 1) {
}
else { hideTable();
currentRow = pageSize * page + 1;
maxRow = currentRow + pageSize;
if (maxRow > numberRowsInTable) maxRow = numberRowsInTable+1;
for (var i = currentRow; i < maxRow; i++) {
theTable.rows[i].style.display = '';
}
page++;
pageNum2.value = page; if (maxRow == numberRowsInTable) { nextText(); lastText(); }
showPage();
if (page == pageCount()) {
nextText();
lastText();
}
preLink();
firstLink();
}
} //上一页
function pre() { if (pageCount() <= 1) {
}
else { hideTable(); page--;
pageNum2.value = page; currentRow = pageSize * page + 1;
maxRow = currentRow - pageSize;
if (currentRow > numberRowsInTable) currentRow = numberRowsInTable;
for (var i = maxRow; i < currentRow; i++) {
theTable.rows[i].style.display = '';
}
if (maxRow == 0) { preText(); firstText(); }
showPage();
if (page == 1) {
firstText();
preText();
}
nextLink();
lastLink();
}
} //第一页
function first() { if (pageCount() <= 1) {
}
else {
hideTable();
page = 1;
pageNum2.value = page;
for (var i = 1; i < pageSize+1; i++) {
theTable.rows[i].style.display = '';
}
showPage(); firstText();
preText();
nextLink();
lastLink();
}
} //最后一页
function last() { if (pageCount() <= 1) {
}
else { hideTable();
page = pageCount(); pageNum2.value = page;
currentRow = pageSize * (page - 1)+1;
for (var i = currentRow; i < numberRowsInTable+1; i++) {
theTable.rows[i].style.display = '';
} showPage();
lastText();
nextText();
preLink();
firstLink();
}
} function hideTable() {
for (var i = 0; i < numberRowsInTable+1; i++) {
theTable.rows[i].style.display = 'none';
}
theTable.rows[0].style.display = '';
} function showPage() {
pageNum.innerHTML = page; } function inforCount() {
spanTotalInfor.innerHTML = numberRowsInTable;
} //总共页数
function pageCount() {
var count = 0;
if (numberRowsInTable % pageSize != 0) count = 1;
return parseInt(numberRowsInTable / pageSize) + count;
} //显示链接
function preLink() { spanPre.innerHTML = "<a href='javascript:pre();'><img src='../Images/Common/back.png'/></a>"; }
function preText() { spanPre.innerHTML = "<img src='../Images/Common/back.png'/>"; } function nextLink() { spanNext.innerHTML = "<a href='javascript:next();'><img src='../Images/Common/front.png'/></a>"; }
function nextText() { spanNext.innerHTML = "<img src='../Images/Common/front.png'/>"; } function firstLink() { spanFirst.innerHTML = "<a href='javascript:first();'><img src='../Images/Common/first.png'/></a>"; }
function firstText() { spanFirst.innerHTML = "<img src='../Images/Common/first.png'/>"; } function lastLink() { spanLast.innerHTML = "<a href='javascript:last();'><img src='../Images/Common/last.png'/></a>"; }
function lastText() { spanLast.innerHTML = "<img src='../Images/Common/last.png'/>"; } //隐藏表格
function hide() {
for (var i = pageSize + 1; i < numberRowsInTable+1 ; i++) {
theTable.rows[i].style.display = 'none';
}
theTable.rows[0].style.display = ''; inforCount(); totalPage.innerHTML = pageCount();
showPage();
pageNum2.value = page; if (pageCount() > 1) {
nextLink();
lastLink();
} } function renovate() {
numberRowsInTable = theTable.rows.length - 1; //table值发生变化 更新分页
for (var i = pageSize + 1; i < numberRowsInTable + 1; i++) {
theTable.rows[i].style.display = 'none';
}
for (var j = 0; j <= 5;j++ ){
if(j>numberRowsInTable)
break;
theTable.rows[j].style.display = '';
}
inforCount(); totalPage.innerHTML = pageCount();
showPage();
pageNum2.value = page; if (pageCount() > 1) {
nextLink();
lastLink();
}
}
hide();
asp.net下用js实现弹出子窗口选定值并返回的更多相关文章
- WPF FileFolderDialog 和弹出子窗口的一些问题
摘要:本文主要是WPF中 FileFolderDialog的相关问题,补充了关于在父窗口弹出子窗口,以及子窗口的相关属性(Data Binding)和命令绑定(Delegate Command)问题, ...
- pyqt5对用qt designer设计的窗体实现弹出子窗口的示例
pyqt5对用qt designer设计的窗体实现弹出子窗口的示例 脚本专栏 python 1. 用qt designer编写主窗体,窗体类型是MainWindow,空白窗口上一个按钮.并转换成mai ...
- JS设置弹出小窗口。
经常上网的朋友可能会到过这样一些网站,一进入首页立刻会弹出一个窗口,或者按一个连接或按钮弹出,通常在这个窗口里会显示一些注意事项.版权信息.警告.欢迎光顾之类的话或者作者想要特别提示的信息.其实制作这 ...
- fancybox 关闭弹出窗口 parent.$.fancybox.close(); 无反应 fancybox 关闭弹出窗口父页面自动刷新,弹出子窗口前后事件
当我们在父页面使用 fancybox 弹出窗口后,如果想自己手动关闭,则可以 function Cancel() { parent.$.fancybox.close(); } 如果关闭没有反应,最好看 ...
- 黄聪:TinyMCE 4 增强 添加样式、按钮、字体、下拉菜单和弹出式窗口
我最喜欢 WordPress 3.9 的更新是使用了 TinyMCE 4.0 编辑器.新的 TinyMCE 看起来看起来更整洁(真正匹配WP仪表板),它有一些非常不错的附加功能.我的很多老主题和插件必 ...
- JS弹出子窗口
目的 在一个主窗口中,点击一个链接, 弹出一个子窗口 , 父窗口保留 在子窗口中点击关闭, 关闭子窗口. 子窗口的位置位于屏幕的中间 实现 main.html <!DOCTYPE html> ...
- DevExpress第三方控件使用实例之ASPxPopupControl弹出子窗体
弹出页面控件:ASPxPopupControl, <dxpc:ASPxPopupControl ID="popubCtr" runat="server" ...
- js自定义弹出框
js自定义弹出框: 代码如下 <html> <head><title>自定义弹出对话框</title> <style type ="te ...
- [转]js来弹出窗口的详细说明
1.警告对话框 <script> alert("警告文字") </script> 2.确认对话框 <script> confirm(" ...
随机推荐
- 【UVA】658 - It's not a Bug, it's a Feature!(隐式图 + 位运算)
这题直接隐式图 + 位运算暴力搜出来的,2.5s险过,不是正法,做完这题做的最大收获就是学会了一些位运算的处理方式. 1.将s中二进制第k位变成0的处理方式: s = s & (~(1 < ...
- 微软阵营稳定的好消息:.NET开源、Visual Studio
自由
今天各个IT社区,头版头条说的是微软.NET开源了.宇宙中最好的IED–Visual Studio Community 2013将免费提供给用户的消息. <宇宙中最强大的开发环境免费了! > ...
- ios常见加密解密方法
在其他平台中经常会计算MD5值,在iOS平台中也提供了该方法,首先需要导入头文件 #import <CommonCrypto/CommonDigest.h> 方法CC_MD5可以获取MD5 ...
- c++,纯虚函数与抽象类
1.纯虚函数的定义: (1)虚函数被“初始化”为0的函数.声明纯虚函数的一般形式是virtual 函数类型 函数名(参数表列) =0;(2)纯虚函数没有函数体:(3)最后面的“=0”并不表示函数返回值 ...
- BZOJ AC300题留念
- BZOJ 3040: 最短路(road) ( 最短路 )
本来想学一下配对堆的...结果学着学着就偏了... 之前 kpm 写过这道题 , 前面的边不理它都能 AC .. 我也懒得去写前面的加边了... 用 C++ pb_ds 库里的 pairing_hea ...
- USACO Cow Pedigrees 【Dp】
一道经典Dp. 定义dp[i][j] 表示由i个节点,j 层高度的累计方法数 状态转移方程为: 用i个点组成深度最多为j的二叉树的方法树等于组成左子树的方法数 乘于组成右子树的方法数再累计. & ...
- CSS长度单位及区别 em ex px pt in
1. css相对长度单位 Ø em 元素的字体高度 Ø ex 字体x的高度 Ø px ...
- 编译原理Tiny语言的定义
Here is the definition for Tiny language The Tiny lexicon is as follows: Keywords: IF ELSE WRITE R ...
- CSipSimple最新版本号(二)--加入视频功能
前面我们编译好了最新版本号的CSipSimple,并且測试已经能够打电话了.如今要把视频功能加上去. 不知道怎么编译的,能够看我的上一篇博文:CSipSimple最新版本号 我们先来看一下之前的项目是 ...