Display only the Checked Items in the CheckBoxList using C#.Net:
I have One CheckBox above the CheckBoxList and its Text as "Show only Selected Items".
My CheckBoxList has 10 items and three items as Selected.
But when I Check the CheckBox, I want to display onl开发者_JAVA技巧y the selected three items in the CheckBoxList. When I uncheck the CheckBox, I want to display all the 10 items and three items as selected.
How to do this?
in the checked event of checkbox of "Show only Selected Items", do loop and check which is checked and if checkbox of checkboxlist is not selected then remove/visible false that item from checkboxlist.
void Check_Clicked(Object sender, EventArgs e)
{
if(chk.Items[i].Selected != true)
chk.visibility = chk.checked;
}
Your aspx page for each checkbox needs the onchecked change
<asp:CheckBox OnCheckedChanged="Check_Clicked" runat="server" />
Your code behind.
void Check_Clicked(Object sender, EventArgs e)
{
//foreach checkbox in your checkbox list
//checkbox.visibility = checkbox.checked;
}
Something like this... this is kind of pseudo code but hopefully the logic behind it is what you're looking for.
精彩评论