客户端方法:
function check(opt)
{
var chk = window.document.getElementById(opt);
if(chk.checked == true)
{
chk.checked = false;
}
else
{
chk.checked = true;
}
}
服务器端方法:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
return;
}
//e.Row.Cells[0].Attributes.Add("style", "display: none;");
if (e.Row.RowType == DataControlRowType.DataRow)//点击Gridview行,选中/取消选中,当前行中的Checkbox
{
//e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='Red';this.style.cursor = 'hand';");
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = c;");
CheckBox ch = ((CheckBox)e.Row.FindControl("CheckBox1"));
ch.Attributes.Add("onclick", "check('" + e.Row.FindControl("CheckBox1").ClientID.Replace("_", "$") + "')");
e.Row.Attributes.Add("onclick", "check('" + e.Row.FindControl("CheckBox1").ClientID.Replace("_", "$") + "')");
}
}