in ItemDataBound event:CheckBox chk = (CheckBox)e.Item.FindControl("CheckBox1");
if (chk != null)
{
e.Item.Attributes["onClick"] = "javascript:document.getElementById('" + chk.UniqueID + "').Checked=true;";
}
if (chk != null)
{
e.Item.Attributes["onClick"] = "javascript:document.getElementById('" + chk.UniqueID + "').Checked=true;";
}
先给每个item加上客户端事件
DataGrid1.Items[i].Attributes.Add("onmouseover","javascript:GridMouseover(" + kk +")");
然后写脚本
function GridMouseover(index)
{
flag=0;
currenti=index;
currentcolor=document.getElementById("Grid1__ctl"+index).style.backgroundColor;
document.getElementById("Grid1__ctl"+index).style.backgroundColor="#b7c4e2";
document.getElementById("Grid1__ctl"+index).style.cursor="hand";
}
以上是变色
可以按照你的想法修改一下
把事件改成onclick
把脚本改称
document.getElementById("checkboxID").checked=true;
注意checkbox在客户端的id的命名规则