您的位置:首页 > 其它

点击textbox弹出模态窗口,选择后返回主页面并赋值textbox

2011-07-29 23:44 661 查看
查看文章
点击textbox弹出模态窗口,选择后返回主页面并赋值textbox
2010-06-24 09:35
模态窗口返回值是个很好用的东西,给用户体验带来了方便的同时,也可能为程序的数据格式规范带来便利。

--------------------------------------父页面--------------------------------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClickTxt.aspx.cs" Inherits="ClickTxt" %>

<!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 language="javascript" type="text/javascript">
function OpenWin(width,height)
{
var me;
// 把父页面窗口对象当作参数传递到对话框中,以便对话框操纵父页自动刷新。
me = window;
// 显示对话框。
var a = window.showModalDialog("Pager.aspx",me,'dialogWidth='+width +'px;dialogHeight='+height+'px;help:no;status:no')
if(typeof(a) != "undefined")

//返回值赋给TextBox
window.document.getElementById("TextBox1").value = a;
//alert(a);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>
</body>
</html>

public partial class ClickTxt : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onclick", "javascript:OpenWin(540,400)");
}
}

----------------------------------------模态窗口------------------------------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pager.aspx.cs" Inherits="Pager" %>

<!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" />

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="CSGPBH" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" OnDataBound="GridView1_DataBound" OnPageIndexChanging="GridView1_PageIndexChanging" >
<PagerTemplate>
<table width="800px" style="border: 0px; border-style: ridge;" align="center">
<tr>
<td style="border-bottom-style: ridge; width: 100%; text-align: center">
<asp:Label ID="lblCurrrentPage" runat="server" ForeColor="#CC3300"></asp:Label>
<span>跳转至</span>
<asp:DropDownList ID="page_DropDownList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="page_DropDownList_SelectedIndexChanged">
</asp:DropDownList>
<span>页</span>
<asp:LinkButton ID="lnkBtnFirst" CommandArgument="First" CommandName="page" runat="server">第一页</asp:LinkButton>
<asp:LinkButton ID="lnkBtnPrev" CommandArgument="prev" CommandName="page" runat="server">上一页</asp:LinkButton>
<asp:LinkButton ID="lnkBtnNext" CommandArgument="Next" CommandName="page" runat="server">下一页</asp:LinkButton>
<asp:LinkButton ID="lnkBtnLast" CommandArgument="Last" CommandName="page" runat="server">最后一页</asp:LinkButton>
</td>
</tr>
</table>
</PagerTemplate>
<Columns>
<asp:BoundField DataField="CSGPBH" HeaderText="挂牌编号" SortExpression="CSGPBH" />
<asp:BoundField DataField="FWBH" HeaderText="房屋编号" ReadOnly="True" SortExpression="FWBH" />
<asp:BoundField DataField="CQZH" HeaderText="产权证号" SortExpression="CQZH" />
<asp:BoundField DataField="QLR" HeaderText="权利人" SortExpression="QLR" />
<asp:BoundField DataField="QLRZJHM" HeaderText="证件号码" SortExpression="QLRZJHM" />
<asp:BoundField DataField="FBZL" HeaderText="房屋坐落" SortExpression="FBZL" />
<asp:BoundField DataField="MC" HeaderText="挂牌币种" SortExpression="GPBZ" />
<asp:BoundField DataField="GPJG" HeaderText="挂牌价格" SortExpression="GPJG" />
<asp:BoundField DataField="GPZT" HeaderText="挂牌状态" SortExpression="GPZT" />
<asp:BoundField DataField="DJHM" HeaderText="登记号码" SortExpression="DJHM" />
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:clf %>"
SelectCommand="SELECT csgp.[CSGPBH], csgp.[FWBH], csgp.[FBZL], [ZD_A063].[MC], csgp.[GPJG], [ZD_A110].[MC] as GPZT, csgp.[QLR], csgp.[QLRZJHM], csgp.[CQZH], csgp.[DJHM] FROM [YW_CLF_CSGP] csgp JOIN [ZD_A063] ON csgp.[GPBZ] = [ZD_A063].[DM] JOIN [ZD_A110] ON csgp.[GPZT] = [ZD_A110].[DM]"></asp:SqlDataSource>
</form>
</body>
</html>

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;

public partial class Pager : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
//getData();//绑定数据方法
//change_BackColor();
}
}

protected void GridView1_DataBound(object sender, EventArgs e)
{
//取得显示分页界面的那一行
GridViewRow pagerRow = GridView1.BottomPagerRow;
if (pagerRow != null)
{
//取得第一页。上一页。下一页。最后一页的超级链接
LinkButton lnkBtnFirst = (LinkButton)pagerRow.Cells[0].FindControl("lnkBtnFirst");
LinkButton lnkBtnPrev = (LinkButton)pagerRow.Cells[0].FindControl("lnkBtnPrev");
LinkButton lnkBtnNext = (LinkButton)pagerRow.Cells[0].FindControl("lnkBtnNext");
LinkButton lnkBtnLast = (LinkButton)pagerRow.Cells[0].FindControl("lnkBtnLast");

//设置何时应该禁用第一页。上一页。下一页。最后一页的超级链接
if (GridView1.PageIndex == 0)
{
lnkBtnFirst.Enabled = false;
lnkBtnPrev.Enabled = false;
}
else if (GridView1.PageIndex == GridView1.PageCount - 1)
{
lnkBtnNext.Enabled = false;
lnkBtnLast.Enabled = false;
}
else if (GridView1.PageCount <= 0)
{
lnkBtnFirst.Enabled = false;
lnkBtnPrev.Enabled = false;
lnkBtnNext.Enabled = false;
lnkBtnLast.Enabled = false;
}
//从显示分页的行中取得用来显示页次与切换分页的DropDownList控件
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("page_DropDownList");

//根据欲显示的数据源的总页数,创建DropDownList控件的下拉菜单内容
if (pageList != null)
{
int intPage;
for (intPage = 0; intPage <= GridView1.PageCount - 1; intPage++)
{
//创建一个ListItem对象来存放分页列表
int pageNumber = intPage + 1;
ListItem item = new ListItem(pageNumber.ToString());

//交替显示背景颜色
switch (pageNumber % 2)
{
case 0: item.Attributes.Add("style", "background:#CDC9C2;");
break;
case 1: item.Attributes.Add("style", "color:red; background:white;");
break;
}
if (intPage == GridView1.PageIndex)
{
item.Selected = true;
}
pageList.Items.Add(item);
}
}
//显示当前所在页数与总页数
Label pagerLabel = (Label)pagerRow.Cells[0].FindControl("lblCurrrentPage");

if (pagerLabel != null)
{

int currentPage = GridView1.PageIndex + 1;
pagerLabel.Text = "第" + currentPage.ToString() + "页(共" + GridView1.PageCount.ToString() + " 页)";

}
}

}

protected void page_DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
//取得显示分页界面的那一行
GridViewRow pagerRow = GridView1.BottomPagerRow;
//从显示页数的行中取得显示页数的DropDownList控件
DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("page_DropDownList");
//将GridView移至用户所选择的页数
GridView1.PageIndex = pageList.SelectedIndex;
//getData();不用数据源需要绑定
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
//点击返回当前行第6列的值
e.Row.Attributes.Add("onclick", "window.returnValue=\"" + e.Row.Cells[5].Text.Trim() + "\";window.close();");

////当有编辑列时,避免出错,要加的RowState判断
//if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
//{
// ((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
//}

//对指定单元格设置背景颜色
if (e.Row.Cells[8].Text == "待挂牌")
{
e.Row.Cells[8].BackColor = System.Drawing.Color.Yellow;
}
else if (e.Row.Cells[8].Text == "已挂牌")
{
e.Row.Cells[8].BackColor = System.Drawing.Color.YellowGreen;
}
else if (e.Row.Cells[8].Text == "已回退")
{
e.Row.Cells[8].BackColor = System.Drawing.Color.Red;
}
else if (e.Row.Cells[8].Text == "已签约")
{
e.Row.Cells[8].BackColor = System.Drawing.Color.Violet;
}
else
{
e.Row.Cells[8].BackColor = System.Drawing.Color.White;
}

}
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}

}

protected void change_BackColor()
{
for (int j = 0; j <= GridView1.PageCount - 1; j++)
{
for (int i = 0; i <= GridView1.PageSize - 1; i++)
{
GridViewRow row = GridView1.Rows[i];
string gpzt = row.Cells[3].Text.ToString(); //获取挂牌状态所在单元格
if (gpzt == "0")
{
GridView1.Rows[i].Cells[3].BackColor = System.Drawing.Color.Yellow;
}
else if (gpzt == "1")
{
GridView1.Rows[i].Cells[3].BackColor = System.Drawing.Color.GreenYellow;
}
else if (gpzt == "2")
{
GridView1.Rows[i].Cells[3].BackColor = System.Drawing.Color.Red;
}
else if (gpzt == "3")
{
GridView1.Rows[i].Cells[3].BackColor = System.Drawing.Color.Violet;
}
else
{
GridView1.Rows[i].Cells[3].BackColor = System.Drawing.Color.White;
}
}
}
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bind();
}

protected void bind()
{
GridView1.DataSourceID = "SqlDataSource1";
GridView1.DataBind();
}

}
-----------------------------------------------------------------------------------------------

值得一提的是window.returnValue只有一个返回值,如果要返回多个返回值就需要对这个返回值

进行处理可以适当加连接符&,-,+等等,returnValue类型不限制,对于字符串类型,最大为4096个字符。

var array = a.split( "&");

window.document.getElementById("textbox1").value = array[0];
window.document.getElementById("textbox2").value = array[1];

----by handy,2010-6-24

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐