开发者

Display only the Checked Items in the CheckBoxList using C#.Net:

开发者 https://www.devze.com 2023-04-11 18:20 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号