62,046
社区成员
发帖
与我相关
我的任务
分享
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server"
oncheckedchanged="chkAll_CheckedChanged" Text="全选" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkItem" runat="server" />
</ItemTemplate>
</asp:TemplateField>
protected void chkAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkAll = (CheckBox)sender;
foreach (GridViewRow gvRow in GridView1.Rows)
{
CheckBox chkItem = (CheckBox)gvRow.FindControl("chkItem");
chkItem.Checked = chkAll.Checked;
}
}
。。。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标在某行,更改背景色
e.Row.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.backgroundColor='#F9D79C'");
//当鼠标离开,还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
//鼠标变小手 ondblclick双击onClick单击
e.Row.Attributes["style"] = "Cursor:hand";
e.Row.Attributes.Add("onClick", "alert('我单击了这一行!')");
}
<script type="text/javascript">
$(function () {
//全选
$("#chkAll").click(function () {
$("input[name='checkbox']").attr("checked", "true");
});
});
</script>