DataList中嵌套DataList,里面的Datalist里面的Checkbox部分不能选中
我在一个DatList里面嵌套了另一个DataList,而里面的DataList里面有CheckBox,可是我写的程序,总有一个固定的CheckBox选中不了,请大家帮我看看什么原因哈。
前台代码:
<asp:DataList ID="DLApp" runat="server">
<ItemTemplate>
<asp:Label ID="应用程序标识Label" runat="server" Visible="false" Text='<%# Eval("应用程序标识") %>' />
<br />
名称:
<asp:Label ID="名称Label" runat="server" Text='<%# Eval("名称") %>' />
<asp:DataList ID="DLRoleList" runat="server" DataSourceID="dsRoleList" RepeatColumns="5"
RepeatDirection="Horizontal" onitemdatabound="DLRoleList_ItemDataBound">
<ItemTemplate>
<asp:Label ID="RoleID" runat="server" Text='<%# Eval("角色标识") %>' Visible="False" />
<br />
<asp:CheckBox ID="cbrole" runat="server" AutoPostBack="true" />
<asp:Label ID="lblRoleName" runat="server" Text='<%# Eval("角色名称") %>'></asp:Label>
(
<asp:Label ID="角色描述Label" runat="server" Text='<%#(bool)(Eval("角色描述").ToString()=="")?"无描述":Eval("角色描述") %>' />
)<br />
<br />
</ItemTemplate>
</asp:DataList>
<hr style="width: 100%" />
<asp:SqlDataSource ID="dsRoleList" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM "系统应用程序角色表" WHERE ("应用程序标识" = :应用程序标识)">
<SelectParameters>
<asp:ControlParameter ControlID="应用程序标识Label" Name="应用程序标识" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:DataList>
后台代码:
protected void DLRoleList_ItemDataBound(object sender, DataListItemEventArgs e)
{
string[] alroleid = { };
alroleid = Session["roleid"] as string[];
if (alroleid != null)
{
for (int i = 0; i < DLApp.Items.Count; i++)
{
DataList dl = (DataList)DLApp.Items[i].FindControl("DLRoleList");
for (int j = 0; j < dl.Items.Count; j++)
{
CheckBox cb = (CheckBox)dl.Items[j].FindControl("cbrole");
Label lbid = (Label)dl.Items[j].FindControl("RoleID");
if (alroleid.Contains(lbid.Text))
{
cb.Checked = true;
}
else
{
cb.Checked = false;
}
}
}
}
}
有不清楚的说出来哈。谢谢大家了