问题描述如下:
在 webform1中有一个text1和个button1. 点button1调出webform2.在webfrom2中用GridView显示资料(来自sql)。我想通过双击GirdView中的某行把所选取选的行的某列的值传回给调用webform2的text1.text属性.
请问 双击事件和传值 怎么实现??
在 webform1中有一个text1和个button1. 点button1调出webform2.在webfrom2中用GridView显示资料(来自sql)。我想通过双击GirdView中的某行把所选取选的行的某列的值传回给调用webform2的text1.text属性.
请问 双击事件和传值 怎么实现??
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="webform1.aspx.cs" Inherits="CSDN_webform1" %><!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>
</head>
<body>
<form id="form1" runat="server">
<input id="Text1" runat="server" type="text" />
<input id="Button1" type="button" value="button" onclick="window.open('webform2.aspx');" />
</form>
</body>
</html>
********************************************
然后在webform2.aspx里作如下处理:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
DataRowView row = e.Row.DataItem as DataRowView;
e.Row.Attributes.Add("ondblclick", "opener.document.getElementById('Text1').value='"+row["field1"].ToString()+"';window.close();");
}
}
//首先计算要分页的记录总数
SqlCommand MyCommand=new SqlCommand("select count(*) from ygwage where ygid LIKE " + "'"+ TextBox1.Text + "%" + "'AND wagedate BETWEEN @LowerDate AND @UpperDate", MyConnection);
MyCommand.Parameters.Add(new SqlParameter("@LowerDate", SqlDbType.DateTime));
MyCommand.Parameters["@LowerDate"].Value = Convert.ToDateTime(TextBox2.Text);
MyCommand.Parameters.Add(new SqlParameter("@UpperDate", SqlDbType.DateTime));
MyCommand.Parameters["@UpperDate"].Value = Convert.ToDateTime(TextBox3.Text);
MyConnection.Open();
int recordCount=(int)MyCommand.ExecuteScalar();
//设置AspNetPager的RecordCount属性值为要分页的记录总数
this.AspNetPager1.RecordCount=recordCount;
MyCommand.Parameters.Clear();
//然后获取数据
MyCommand = new SqlCommand("select * from ygwage where ygid LIKE " + "'"+ TextBox1.Text + "%" + "'AND wagedate BETWEEN @LowerDate AND @UpperDate", MyConnection);
MyCommand.Parameters.Add(new SqlParameter("@LowerDate", SqlDbType.DateTime));
MyCommand.Parameters["@LowerDate"].Value = Convert.ToDateTime(TextBox2.Text);
MyCommand.Parameters.Add(new SqlParameter("@UpperDate", SqlDbType.DateTime));
MyCommand.Parameters["@UpperDate"].Value = Convert.ToDateTime(TextBox3.Text);
SqlDataAdapter adapter=new SqlDataAdapter(MyCommand);
DataSet ds=new DataSet();
adapter.Fill(ds,AspNetPager1.PageSize*(AspNetPager1.CurrentPageIndex-1),AspNetPager1.PageSize,"ygwage");
AspNetPager1.CustomInfoText = "第<font color='red'><b>" + AspNetPager1.CurrentPageIndex.ToString() +
"</b></font>页/共<font color='blue'><b>" + AspNetPager1.PageCount.ToString() +
"</b></font>页 每页<font color='blue'><b>" + AspNetPager1.PageSize.ToString() +
"</b></font>条/共<font color='blue'><b>" + AspNetPager1.RecordCount.ToString() +
"</b></font>条";
DataGrid1.DataSource = ds.Tables[0];
DataGrid1.DataKeyField = "ygid";
DataGrid1.DataBind();
if(MyConnection.State!=ConnectionState.Closed)
MyConnection.Close();
if(this.DataGrid1.Items.Count<1)
{
Message.Text="没有你查询的内容!";
Message.Visible=true;
Button2.Enabled=false;
//Message1.Visible=false; }
else
{
Message.Visible=false;
Button2.Enabled=true;
//循环对表格行做脚本,点击弹出新窗口
int i=0;
int mycount = DataGrid1.Items.Count;
string ygid = "";
string wagedate = ""; for(i=0;i<mycount;i++)
{
ygid = DataGrid1.DataKeys[i].ToString();
wagedate = DataGrid1.Items[i].Cells[6].Text;
//DataGrid1.Items[i].Attributes.Add("onclick","window.open('updatawage.aspx?ygid=" + ygid + "','','');");//单击响应
//DataGrid1.Items[i].Attributes.Add("ondblclick","window.open('updatawage.aspx?ygid=" + ygid + "','','');");//双击响应
DataGrid1.Items[i].Attributes.Add("ondblclick","window.open('updatawage.aspx?ygid=" + ygid + "&wagedate="+ wagedate +" ','','');");
} }dataview差不多,你自己改改