使用 C#.Net 仅显示 CheckBoxList 中选中的项目:

发布于 2024-12-08 14:59:44 字数 193 浏览 6 评论 0原文

我在 CheckBoxList 上方有一个复选框,其文本为“仅显示所选项目”。

我的 CheckBoxList 有 10 个项目,其中 3 个项目为“选定”。

但是当我检查复选框时,我只想显示 CheckBoxList 中选定的三个项目。 当我取消选中复选框时,我想显示所有 10 个项目和选定的三个项目。

如何做到这一点?

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 only 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱要勇敢去追 2024-12-15 14:59:44

在“仅显示所选项目”复选框的选中事件中,循环并检查哪个已选中,如果未选中复选框列表的复选框,则从复选框列表中删除/可见该项目。

void Check_Clicked(Object sender, EventArgs e) 
{
    if(chk.Items[i].Selected != true)
        chk.visibility = chk.checked;
}

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;
}
不回头走下去 2024-12-15 14:59:44

每个复选框的 aspx 页面都需要 onchecked 更改

  <asp:CheckBox OnCheckedChanged="Check_Clicked" runat="server" />

您后面的代码。

  void Check_Clicked(Object sender, EventArgs e) 
  {
    //foreach checkbox in your checkbox list
    //checkbox.visibility = checkbox.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文