首先为gridView添加一个模板域,选择编辑模板,把复选框拖入到相应位置(布局--->位置--->未设置).
<script type="text/javascript">
function check(chk)
{
var items = document.getElementsByTagName("input");
for(var i = 0; i < items.length; i++)
{
if(items[i].type == "checkbox")
items[i].checked = chk.checked;
}
}
</script>
<asp:CheckBox ID="chkAll" οnclick="check(this)" runat="server" Text="全选" />
光棒:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentColor=this.style.backgroundColor;this.style.backgroundColor='#E9E9DC'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentColor");
}
}