enable/disable checkbox based on a Condition

Feb 3 2020 4:35 PM

I have a checkbox that comes from DB inside repeater. I have to disable few checkboxes based on a click of one checkbox. and disable one particular checkbox based on the click of any other checkboxes.

 
aspx page


<div style="float:left; max-width:710px;">

<div class="miniForm" style="max-width:700px;">

<asp:Repeater ID="rptPrivilegeCheckboxes" runat="server" EnableViewState="true" OnItemDataBound="rptPrivilegeCheckboxes_ItemDataBound">

<ItemTemplate>

<div class="pDiv mb10">

<div class="elementDiv fl" style="width:220px;"><asp:CheckBox ID="chkPrivilege" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "PrivilegeName") %>' /></div>

<div class="elementDiv fl" style="width:450px;">

<%# DataBinder.Eval(Container.DataItem, "PrivilegeDescription")%><br />

<span style="font-style:italic; color:#890000;">* <%# DataBinder.Eval(Container.DataItem, "Instruction")%></span>

</div>

<br clear="all" />

</div>

</ItemTemplate>

</asp:Repeater>

</div>

</div>

 
 
C# page
 

protected void rptPrivilegeCheckboxes_ItemDataBound(object sender, RepeaterItemEventArgs e)

{

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

{

string privValue = DataBinder.Eval(e.Item.DataItem, "PrivilegeID").ToString();

((CheckBox)e.Item.FindControl("chkPrivilege")).InputAttributes.Add("Value", privValue);

}

}

 

Answers (2)