如何隐藏复选框列表中未选中的项目?
我有一个从 XML 文件获取数据的复选框列表。如果用户选择复选框列表上的某个项目,我只想显示该项目并隐藏其他所有内容。在其下方,我想添加可点击的文本,以便用户选择其他内容。因此,如果用户单击该文本,用户将再次看到复选框列表,并选择第一个项目。
基本上看起来是这样的。 那么我们如何实现这一目标呢?
非常感谢。
需要使用 vb.net/和 checkboxlist 控件,因为我们将从数据库动态进行数据绑定。
I have a checkboxlist which gets the data from XML file. If a user selects an item on checkboxlist, i just want to show that item and hide everything else. And beneath that, I want to add clickable text to let the use to choose something else. So if the use click on that text, the user will see the checkboxlist again with the first item selected.
Basically look like this.
So how do we achieve this?
Thanks so much.
require to use vb.net/and checkboxlist control as we will be databinding dynamically from database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种方法。使用两个面板作为两个不同的 CheckBoxList 的容器。第一个显示您的“FROM”项目,后者显示您的“TO”项目。
第二个面板最初是不可见的。除了 CheckBoxList 之外,它还包含一个 LinkButton 来触发取消选择。
在
BtnSelect
上单击,您将从第一个复选框添加所选项目到第二个 CheckBoxList 并显示其面板。在BtnChangeSelection
上 - 单击您只需切换两个面板的可见性并选择第一项。这已经适用于多重选择。
ASPX(CSS 取决于您):
代码隐藏:
为了完整起见,这是我的示例代码的其余部分:
Here is one way. Use two Panels as container for two different CheckBoxLists. The first displays your "FROM"-Items and the latter your "TO"-Items.
The second panel is initially invisivle. Apart from the CheckBoxList it contains a LinkButton to trigger the deselection.
On
BtnSelect
-Click you'll add the selected items from the first to the second CheckBoxList and show it's Panel. OnBtnChangeSelection
-Click you only need to switch visibiliy of both Panels and select first item.This already works with multiple selection.
ASPX (CSS is up to you):
Codebehind:
This is the rest of my sample-code, for the sake of completeness:
我绝对建议完全使用 jQuery 来完成此操作。它既光滑又快速。
HTML
这将由您的
生成,您不必担心使用它,它只是在这里供参考。< /sub>Javascript
这是您将添加到脚本中以启用所需功能的内容。
这是一个工作的 jsfiddle。
我还没有在
asp:Checkboxlist
上测试过它,但这应该可以工作,因为我没有使用任何硬编码id
的。I would definitely recommend doing this entirely with jQuery. It's slick and quick.
HTML
this wil be generated by your
<asp:CheckboxList />
, you don't have to worry about using it, it's just here for reference.Javascript
this is what you'll add to your scripts in order to enable what you need.
Here's a working jsfiddle.
I haven't tested it on an
asp:Checkboxlist
, but this should work since I'm not using any hardcodedid
's.