日期:2014-05-18  浏览次数:20401 次

请教关于gridview中使用带checkbox的模板列和行单击事件分离的问题?急,在线等……
我在gridview的模板列中添加checkbox,用于选中行;同时在后台中注册了行的onclick事件,代码:e.Row.Attributes.Add( "onmousedown ",   "javascript:show( ' "+e.Row.Cells[2].Text.ToString().Trim()+ " '); ");
我想要实现在checkbox   check选择时不触发注册的行的onclick事件,在行onclick时不触发check事件这样的功能,即带有checkbox的模板列和其他行分离,不注册行的onclick事件!有人做过类似的功能吗?先谢谢了!


------解决方案--------------------
> > > >

// 要点:取消事件冒泡
// FF 事件模型请 baidu/google, 不熟悉
// IE 方式如下,
e.Row.Attributes.Add( "onmousedown ", "javascript:show( ' "+e.Row.Cells[2].Text.ToString().Trim()+ " ');event.returnValue=false;event.cancelBubble=true; ");


<asp:checkbox onclick= "event.returnValue=false;event.cancelBubble=true; " ...
------解决方案--------------------
sorry, ->

<asp:checkbox onclick= "event.cancelBubble=true; " ...
------解决方案--------------------
假设带有checkbox的模板列是第1列

e.Row.Attributes.Add( "onmousedown ", "javascript:show( ' "+e.Row.Cells[2].Text.ToString().Trim()+ " '); ");
e.Row.Cells[0].Attributes.Add( "onclick ", "event.cancelBubble=true;return false; ");

------解决方案--------------------
<asp:checkbox onclick="event.cancelBubble=true;" ...

用3楼的这个就可以啦。。。

刚才在DATALIST里面测试通过。。