有时候,我们不需要用CheckBoxList,这时就不能得到选中的值,其实,我们可以把值存在ViewState中,这样在服务器端可以取出来。
Code
public class ValueCheckBox : CheckBox
{
[Description("值"), DefaultValue(false),Bindable(true)]
public string Value
{
get
{
return null == ViewState["Value"] ? string.Empty : (string)ViewState["Value"];
}
set { ViewState["Value"] = value; }
}
}
public class ValueCheckBox : CheckBox
{
[Description("值"), DefaultValue(false),Bindable(true)]
public string Value
{
get
{
return null == ViewState["Value"] ? string.Empty : (string)ViewState["Value"];
}
set { ViewState["Value"] = value; }
}
}
Code
<%@ Control Inherits="Grain.Web.Manage.Facade.Controls.RoleOperatorControl" Language="C#" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (RepeaterItem riMenu in this.repMenu.Items)
{
Repeater repOper = riMenu.FindControl("repOper") as Repeater;
foreach (RepeaterItem ri in repOper.Items)
{
ValueCheckBox vcb = ri.FindControl("ckOper") as ValueCheckBox;
if (vcb != null && vcb.Checked)
{
Response.Write(vcb.Value + "<br/>");
}
}
}
}
</script>
<div>
<facade:RoleDropDownList ID="ddlRole" runat="server">
</facade:RoleDropDownList>
<asp:Repeater runat="server" ID="repMenu">
<HeaderTemplate>
<div>
</HeaderTemplate>
<ItemTemplate>
<asp:Panel runat="server" ID="panelMenu">
<asp:Panel runat="server" ID="panelMenuName"><%#Eval("Name") %></asp:Panel>
<asp:Repeater runat="server" ID="repOper" DataSource='<%#Eval("DicOperates") %>'>
<HeaderTemplate><li></HeaderTemplate>
<ItemTemplate><span><facade:ValueCheckBox runat="server" ID="ckOper" Text='<%#Eval("DescSy") %>' Value='<%#Eval("Id") %>' /></span></ItemTemplate>
<FooterTemplate></li></FooterTemplate>
</asp:Repeater>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
<asp:Button runat="server" ID="btnSave" Text="确认授权" onclick="btnSave_Click" />
</div>
<%@ Control Inherits="Grain.Web.Manage.Facade.Controls.RoleOperatorControl" Language="C#" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (RepeaterItem riMenu in this.repMenu.Items)
{
Repeater repOper = riMenu.FindControl("repOper") as Repeater;
foreach (RepeaterItem ri in repOper.Items)
{
ValueCheckBox vcb = ri.FindControl("ckOper") as ValueCheckBox;
if (vcb != null && vcb.Checked)
{
Response.Write(vcb.Value + "<br/>");
}
}
}
}
</script>
<div>
<facade:RoleDropDownList ID="ddlRole" runat="server">
</facade:RoleDropDownList>
<asp:Repeater runat="server" ID="repMenu">
<HeaderTemplate>
<div>
</HeaderTemplate>
<ItemTemplate>
<asp:Panel runat="server" ID="panelMenu">
<asp:Panel runat="server" ID="panelMenuName"><%#Eval("Name") %></asp:Panel>
<asp:Repeater runat="server" ID="repOper" DataSource='<%#Eval("DicOperates") %>'>
<HeaderTemplate><li></HeaderTemplate>
<ItemTemplate><span><facade:ValueCheckBox runat="server" ID="ckOper" Text='<%#Eval("DescSy") %>' Value='<%#Eval("Id") %>' /></span></ItemTemplate>
<FooterTemplate></li></FooterTemplate>
</asp:Repeater>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
<asp:Button runat="server" ID="btnSave" Text="确认授权" onclick="btnSave_Click" />
</div>