如何通过单击鼠标在datagridview中打勾复选框? [英] How can tick check box in datagridview with mouse click?

查看:432
本文介绍了如何通过单击鼠标在datagridview中打勾复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有带标签的datagridview,同时单击gridview行中的任何标签,然后我要选中相应行的复选框...请给我一些示例代码....

Hi to All,
I have datagridview with labels, while click any label in the gridview row then i want to check checkbox with respective row... please send me some sample code ....

推荐答案

1.Add Itemplate as label
and call javscript function on onclick event of label with passing id of this label.

code:

<ItemTemplate >
<asp:Label ID="lblCompany" runat="server" Text='<%# Bind("Company")%>' onClick="return FunctionName(event,this);" contentEditable="true"></asp:Label>
</ItemTemplate>


javscript:
fucntion functionname(e,ctrl)
{

//from this you can get current row index and cellindex by using this you can make

var row=ctrl.offsetParent.parentNode.rowIndex;
var cell=ctrl.offsetParent.cellIndex;

var gdv = document.getElementById('GridView1');
gdv.rows(row).cells(column number of your checkbox column).children.item(0).checked=true;

}



Or

2.you directly call javascript function on gridview click

code:

<asp:GridView ID="GridView1" runat="server" Width="80%"  onClick="return return FunctionName(event,this);" >

javscript:

fucntion functionname(e,ctrl)
{

var gdv = document.getElementById('GridView1');

//from this you can get current row index and cellindex by using this you can make

var row=ctrl.document.activeElement.parentElement.rowIndex;
var cell=ctrl.document.activeElement.cellIndex;

gdv.rows(row).cells(column number of your checkbox column).children.item(0).checked=true;

}

I hope it helps you


这篇关于如何通过单击鼠标在datagridview中打勾复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆