当前位置:IT168首页 > 技术开发 > 概述
[收藏此页] [打印] [推荐] [评论]

扩展GridView控件 - 响应行的单击事件和双击事件

责任编辑:nancy作者:ITPUB论坛   2008-05-14   
【内容导航】
文本Tag: 微软 sql

【IT168技术文档】

  扩展GridView控件:
  响应行的单击事件和双击事件,并在服务端处理

  使用方法(设置属性):
  BoundRowClickCommandName - 行的单击事件需要绑定的CommandName
  BoundRowDoubleClickCommandName - 行的双击事件需要绑定的CommandName


  单击
using System; using System.Collections.Generic; using System.Text; using System.Web.UI.WebControls; using System.Web.UI; namespace YYControls.SmartGridViewFunction { /**//// <summary> /// 扩展功能:响应行的单击事件 /// </summary> public class RowClickFunction : ExtendFunction { List<string> _rowClickButtonUniqueIdList = new List<string>(); /**//// <summary> /// 构造函数 /// </summary> public RowClickFunction() : base() { } /**//// <summary> /// 构造函数 /// </summary> /// <param name="sgv">SmartGridView对象</param> public RowClickFunction(SmartGridView sgv) : base(sgv) { } /**//// <summary> /// 扩展功能的实现 /// </summary> protected override void Execute() { this._sgv.RowDataBoundCell += new SmartGridView.RowDataBoundCellHandler(_sgv_RowDataBoundCell); this._sgv.RenderBegin += new SmartGridView.RenderBeginHandler(_sgv_RenderBegin); } /**//// <summary> /// RowDataBoundCell /// </summary> /// <param name="sender"></param> /// <param name="gvtc"></param> void _sgv_RowDataBoundCell(object sender, GridViewTableCell gvtc) { TableCell tc = gvtc.TableCell; foreach (Control c in tc.Controls) { IButtonControl ibc = c as IButtonControl; if (ibc != null && this._sgv.BoundRowClickCommandName == ibc.CommandName) { // 300毫秒后响应单击事件的脚本(避免和双击事件冲突) string js = this._sgv.Page.ClientScript.GetPostBackClientHyperlink(c, ""); js = js.Insert(11, "setTimeout(\""); js += "\", 300)"; GridViewRow gvr = tc.Parent as GridViewRow; Helper.Common.SetAttribute(gvr, "onclick", js, AttributeValuePosition.Last); _rowClickButtonUniqueIdList.Add(c.UniqueID); } } } /**//// <summary> /// RenderBegin /// </summary> /// <param name="sender"></param> /// <param name="writer"></param> void _sgv_RenderBegin(object sender, HtmlTextWriter writer) { foreach (string uniqueId in this._rowClickButtonUniqueIdList) { // 注册回发或回调数据以进行验证 this._sgv.Page.ClientScript.RegisterForEventValidation(uniqueId); } } } }
上一页
1
2下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/d/2008-05-14/200805142234828.shtml
技术开发相关文章   .net server SQL 微软
  • 暂无
友情推介