为什么点击文本框里面的按钮弹出对话框后,文本框的失去焦点事件没有执行呢???%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %><!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>
<style type="text/css">
.noborder{border-width:0px;margin:0px;}
.hasborder{border-width:0px;background:;padding:0px}
.cssbtn{width:20px;height:20px;padding:0px;}
</style>
<script type="text/javascript">
function showEdit(r,c)
{
var src=eval(document.forms[0].elements["txt"+r+"_"+c])
src.readOnly=false;
src.className='hasborder';
src.select();
var btn=document.createElement("input");
btn.type="button";
btn.className="cssbtn";
btn.value="?";
btn.onclick=a;
event.srcElement.parentNode.appendChild(btn);
}
function a()
{
alert("你好!");
}
function lostfocus(o)
{
o.className='noborder';
o.readOnly=true;
if (document.getElementById("cz"))
o.parentNode.removeChild(document.getElementById("cz"));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" ShowHeader="False" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="加载表格" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="保存数据" OnClick="Button2_Click" />
<asp:Label ID="ret" runat="server" Text="Label"></asp:Label>
<br />
</div>
</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 Default3 : System.Web.UI.Page
{
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView dv = (DataRowView)e.Row.DataItem;
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("ondblclick","showEdit("+e.Row.RowIndex.ToString()+","+i.ToString()+")");
e.Row.Cells[i].Text = "<input onblur='lostfocus(this)' name='txt" + e.Row.RowIndex.ToString() + "_" + i.ToString() + "' readonly='readonly' class='noborder' maxlength='4' value='" + dv[i].ToString() + "'/>";
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = GetData();
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
string s = string.Empty;
for (int i = 0; i< 5; i++)
{
for (int j = 0; j < 5; j++)
{
s=s+"<li>第 " + i.ToString() + " 行第 " + j.ToString() + " 列的值是:" + Request.Form["txt" + i.ToString() + "_" + j.ToString()]; }
}
ret.Text = s;
GridView1.DataSource = GetData();
GridView1.DataBind();
}
private DataTable GetData()
{
DataTable dt = new DataTable();
for (int i = 0; i < 5; i++)
{
dt.Columns.Add(new DataColumn("", typeof(System.String)));
}
for (int i = 0; i < 5; i++)
{
dt.Rows.Add(dt.NewRow());
for (int j = 0; j < 5; j++)
{
dt.Rows[i][j] = Request.Form["txt" + i.ToString() + "_" + j.ToString()];
}
}
return dt;
}
}
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.noborder{border-width:0px;margin:0px;}
.hasborder{border-width:0px;background:;padding:0px}
.cssbtn{width:20px;height:20px;padding:0px;}
</style>
<script type="text/javascript">
function showEdit(r,c)
{
var src=eval(document.forms[0].elements["txt"+r+"_"+c])
src.readOnly=false;
src.className='hasborder';
src.select();
var btn=document.createElement("input");
btn.type="button";
btn.className="cssbtn";
btn.value="?";
btn.onclick=a;
event.srcElement.parentNode.appendChild(btn);
}
function a()
{
alert("你好!");
}
function lostfocus(o)
{
o.className='noborder';
o.readOnly=true;
if (document.getElementById("cz"))
o.parentNode.removeChild(document.getElementById("cz"));
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" ShowHeader="False" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="加载表格" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="保存数据" OnClick="Button2_Click" />
<asp:Label ID="ret" runat="server" Text="Label"></asp:Label>
<br />
</div>
</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 Default3 : System.Web.UI.Page
{
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView dv = (DataRowView)e.Row.DataItem;
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("ondblclick","showEdit("+e.Row.RowIndex.ToString()+","+i.ToString()+")");
e.Row.Cells[i].Text = "<input onblur='lostfocus(this)' name='txt" + e.Row.RowIndex.ToString() + "_" + i.ToString() + "' readonly='readonly' class='noborder' maxlength='4' value='" + dv[i].ToString() + "'/>";
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = GetData();
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
string s = string.Empty;
for (int i = 0; i< 5; i++)
{
for (int j = 0; j < 5; j++)
{
s=s+"<li>第 " + i.ToString() + " 行第 " + j.ToString() + " 列的值是:" + Request.Form["txt" + i.ToString() + "_" + j.ToString()]; }
}
ret.Text = s;
GridView1.DataSource = GetData();
GridView1.DataBind();
}
private DataTable GetData()
{
DataTable dt = new DataTable();
for (int i = 0; i < 5; i++)
{
dt.Columns.Add(new DataColumn("", typeof(System.String)));
}
for (int i = 0; i < 5; i++)
{
dt.Rows.Add(dt.NewRow());
for (int j = 0; j < 5; j++)
{
dt.Rows[i][j] = Request.Form["txt" + i.ToString() + "_" + j.ToString()];
}
}
return dt;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货