All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
分离及附加数据库_[SQL Server教程]
C#教程: 注册表的结构
PHP实例:PHP天气查询_[PHP教程]
20个实用PHP实例代码_[PHP教程]
SQL之更多的子查询_[SQL,Server教程]
c#中GDI+图形图像:用直线和曲线消除锯齿
DataSet数据导入Excel的c#代码_[Asp.Net教程]
Visual,C#,2.0泛型编程基础_[Asp.Net教程]
在ASP.NET,2.0中建立站点导航层次_.net资料_编程技术
也谈,.NET2.0中避免分布式事务_.net资料_编程技术
Reading number is top 10 pictures
全球清廉国家排行
Azusa Yamamoto1
On the verge of extinction of the beach1
玩手机对身体不好
Earthquake hedge common sense
穷哥们向美女求婚攻略
Sora aoi mirror memorial classics2
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line2
西班牙山村小景5
The real super beauty12
Download software ranking
Unix video tutorial17
Photoshop 8.0图象编辑软件
matrix1
Sora aoi - one of more PK
matrix2
Tram sex maniac 2 (H) rar bag9
Unix video tutorial2
Eclipse-CALMSANNY (second edition)
Boxer vs Yellow2
ASP.NET.2.0.XML.高级编程(第3版)
归海一刀 published in(发表于) 2014/1/30 1:26:41 Edit(编辑)
DataGrid单击一行服务器事件_[Asp.Net教程]

DataGrid单击一行服务器事件_[Asp.Net教程]

添加GridView/DataGrid单击一行服务器事件_[Asp.Net教程]
实现功能:
asp.net的GridView/DataGrid控件本身均支持行选择事件(通过设置Button/LinkButton.CommandName="Selected",并在 SelectedIndexChanged 事件中处理)。
然而,有时候我们希望用户点击网页上GridView/DataGrid 一行中任意位置都可以实现触发一个事件,并在服务端对此行进行相应处理,现在我们就实现此功能。
实现方式:
这里我们采取的方法有点 "hack" :
通过客户端 javascript 引发行中隐藏的按钮(Button/LinkButton 均可以)的 click 事件。
主要代码:





<%# Eval("ProductName") %>







protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Button btnHiddenPostButton = e.Row.FindControl("btnHiddenPostButton") as Button;
if (btnHiddenPostButton != null) {
e.Row.Attributes["onclick"] = String.Format("javascript:document.getElementById(’{0}’).click()", btnHiddenPostButton.ClientID);
// 额外样式定义
e.Row.Attributes["onmouseover"] = "javascript:this.style.background=’red’";
e.Row.Attributes["onmouseout"] = "javascript:this.style.background=’’";
e.Row.Attributes["style"] = "cursor:pointer";
e.Row.Attributes["title"] = "单击选择当前行";
}
// 若希望将隐藏按钮单独放于一列,则设置此列隐藏,占位符 表示此列索引
//e.Row.Cells[].Attributes["style"] = "display:none";
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = -1;
GridViewRow row = null;
switch (e.CommandName) {
case "HiddenPostButtonCommand": // 模板列
Control cmdControl = e.CommandSource as Control; // 表示触发事件的 IButtonControl,保持统一性并便于后续操作,我们这里直接转化为控件基类 Control
row = cmdControl.NamingContainer as GridViewRow; // 当前行
// 如何访问单元格值
// string txt = row.Cells[0].Text;
// 如何获取模板列中的 Label
// string lbl = row.FindControl("MyLabelID") as Label;
// 执行更多的自定义操作
// ....
// .....
Response.Write(String.Format("GridView Version 当前第 {0} 行:", row.RowIndex + 1));
break;
// case "Command2":
// more cases
// .....
}
}




源程序下载:GridView.rar

转自:http://www.cnblogs.com/Jinglecat/archive/2007/07/15/818394.html


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.