Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sir, i have a checkbox and checkboxlist. i want to true all check of checkboxlist by change of checkbox. My Code:-

<asp:CheckBox ID="CheckBox1" runat="server" />

XML
<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="code" DataValueField="departmentid"
                    RepeatColumns="2"  RepeatDirection="Horizontal">
 </asp:CheckBoxList>



how can i do it..
Posted

 
Share this answer
 
Comments
Maciej Los 3-Dec-14 5:49am    
+5
Abhinav S 3-Dec-14 7:45am    
Thanks.
Hi,

In checkbox changed event you can write the below code


if(checkBox.checked)
{
foreach (ListItem item in checkBoxlist.Items)
{
item.Selected = true;
}
}
else
{
foreach (ListItem item in checkBoxlist.Items)
{
item.Selected = false;
}
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900