是用脚本,我是先做了个模版列,然后通过itemcreated将脚本事件注册到每个checkbox中去
脚本如下:
function SelectOneRow(chkB) {
var xState=chkB.checked;
if(xState)
{
chkB.parentElement.parentElement.style.backgroundColor='lightcoral'; //设置选中的颜色,//chkB.parentElement.parentElement将引用到<tr>节点的对象中,然后设置背景色。
}else
{
chkB.parentElement.parentElement.style.backgroundColor='white';
}
}
获取选中的值,我们可以用foreach的方法来循环查找行集下的checkbox是否为true。当为true,则输出,否则跳过行。
foreach (DataGridItem dgi in DataGrid1.Items)
{
if (((CheckBox)dgi.Cells[0].FindControl("chkOne")).Checked==true)
CustomerID+=dgi.Cells[1].Text;
}
脚本如下:
function SelectOneRow(chkB) {
var xState=chkB.checked;
if(xState)
{
chkB.parentElement.parentElement.style.backgroundColor='lightcoral'; //设置选中的颜色,//chkB.parentElement.parentElement将引用到<tr>节点的对象中,然后设置背景色。
}else
{
chkB.parentElement.parentElement.style.backgroundColor='white';
}
}
获取选中的值,我们可以用foreach的方法来循环查找行集下的checkbox是否为true。当为true,则输出,否则跳过行。
foreach (DataGridItem dgi in DataGrid1.Items)
{
if (((CheckBox)dgi.Cells[0].FindControl("chkOne")).Checked==true)
CustomerID+=dgi.Cells[1].Text;
}