<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Width="100%" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%#Bind("FunctionName") %>' ToolTip='<%#Bind("FunctionID") %>' OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true"/>
<br/><table width="100%"><tr><td width="40px"></td><td><asp:CheckBoxList ID="CheckBoxList2" runat="server" RepeatDirection="Horizontal" RepeatColumns="6">
</asp:CheckBoxList></td></tr></table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>后台:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox HiCb1 = e.Row.FindControl("Checkbox1") as CheckBox;
CheckBoxList cbl = e.Row.FindControl("CheckBoxList2") as CheckBoxList;
fr.GridViewRowDataBound(HiCb1,cbl);//自己写绑定数据源
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{//父节点的选中状态改变时,改变子结点的选中状态
CheckBox cb = sender as CheckBox;
foreach (GridViewRow row in this.GridView1.Rows)
{
CheckBox rowCb=row.FindControl("CheckBox1") as CheckBox;
if (rowCb.ToolTip == cb.ToolTip)
{
CheckBoxList cbl=row.FindControl("CheckBoxList2") as CheckBoxList;
foreach (ListItem li in cbl.Items)
{
li.Selected = cb.Checked;
}
}
}
}
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%#Bind("FunctionName") %>' ToolTip='<%#Bind("FunctionID") %>' OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true"/>
<br/><table width="100%"><tr><td width="40px"></td><td><asp:CheckBoxList ID="CheckBoxList2" runat="server" RepeatDirection="Horizontal" RepeatColumns="6">
</asp:CheckBoxList></td></tr></table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>后台:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox HiCb1 = e.Row.FindControl("Checkbox1") as CheckBox;
CheckBoxList cbl = e.Row.FindControl("CheckBoxList2") as CheckBoxList;
fr.GridViewRowDataBound(HiCb1,cbl);//自己写绑定数据源
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{//父节点的选中状态改变时,改变子结点的选中状态
CheckBox cb = sender as CheckBox;
foreach (GridViewRow row in this.GridView1.Rows)
{
CheckBox rowCb=row.FindControl("CheckBox1") as CheckBox;
if (rowCb.ToolTip == cb.ToolTip)
{
CheckBoxList cbl=row.FindControl("CheckBoxList2") as CheckBoxList;
foreach (ListItem li in cbl.Items)
{
li.Selected = cb.Checked;
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货