1、js代码
<script language="javascript" type="text/javascript">
function chkAll(controlid, chkboxAllID)
{
var chkall = document.getElementById(chkboxAllID);
var chkother = document.getElementsByTagName("input");
for (var i = 0; i < chkother.length; i ++ )
{
if( chkother[i].type == 'checkbox')
{
if(chkother[i].id.indexOf(controlid) > - 1)
{
if(chkall.checked == true)
{
chkother[i].checked = true;
}
else
{
chkother[i].checked = false;
}
}
}
}
} </script>
2 、控件代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" PageSize="8" Width="800px" OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="全选">
<ItemTemplate>
<asp:CheckBox ID="Check" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="CheckBoxAll" runat="server" Text="全选" onclick="chkAll('GridView1', this.id)" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编号">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("User_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="用户ID">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("User_Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="用户名">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("User_RellName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="公司名">
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("user_companyName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="User_RegTime" DataFormatString="{0:d}" HeaderText="注册时间"
HtmlEncode="False" ReadOnly="True" />
<asp:TemplateField HeaderText="是否通过审核">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#MadeStr(Eval("User_Check"))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="等级">
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# FormatUserlevel(Eval("User_UserLevel"))%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddl_userLevel" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="推荐度" DataField="User_tuijiandu" />
<asp:TemplateField HeaderText="查看">
<ItemTemplate>
<a href="UserInfo.aspx?userid=<%#Eval("User_ID") %>">查看</a>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" HeaderText="修改" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>