选择在asp.net的CheckBoxList所有物品 [英] Select All Items in asp.net CheckBoxList
本文介绍了选择在asp.net的CheckBoxList所有物品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ASP.NET和C#。
ASP.NET and C#.
我想有一个全选项的CheckBoxList。
I'd like to have a CheckboxList with a "Select All" item.
- 在当前这个特殊的产品
选择,其他的都会被选中
太。 - 当选择从删除
这个项目,所以也不会是所有
其他项目。 - 检查/中取消勾选
任何其他项目将只有一个
在那个特定的项目影响
不管选择状态的
全选项目。
我在找一个jQuery解决这个。
I am looking for a jquery solution to this.
下面是我的codebehind数据绑定code:
Here is the databinding code in my codebehind:
IList<Central> Centrals = new CentralProvider().GetAllCentralsAsList();
Centrals.Insert(0, new Central(){Central_ID = 999, Central_Name = "Select All"});
CentralChecks.DataSource = Centrals;
CentralChecks.DataTextField = "Central_Name";
CentralChecks.DataValueField = "Central_ID";
CentralChecks.DataBind();
这里是标记:
<div class="CentralDiv" id="CentralDiv">
<h2>Centrals:</h2>
<span>
<asp:TextBox ID="CentralTextBox" runat="server" CssClass="textbox">Centrals</asp:TextBox>
<img id="CentralArrow" src="images/down_arrow.jpg" style="margin-left: -22px; margin-bottom: -5px" />
</span>
<div id="CentralEffect" class="ui-widget-content">
<asp:CheckBoxList ID="CentralChecks" runat="server" onclick="GetSelectedCentralValue();">
</asp:CheckBoxList>
</div>
</div>
请注意,有在页面上有多个复选框列表,因此任何解决方案都必须牢记这一点。
Note that there are multiple checkbox lists on the page, so any solution must keep this in mind.
推荐答案
喜欢的东西,你可以使用任何你的复选框列表,只需添加myCheckBoxList的的CssClass每个CheckBoxList控件:
Something like you could use for any of your checkbox lists, just add a cssclass of myCheckBoxList to each CheckBoxList control:
$('.myCheckBoxList :checkbox').eq(0).click(function() {
var toggle = this.checked;
$('.myCheckBoxList :checkbox').attr("checked", toggle);
});
这篇关于选择在asp.net的CheckBoxList所有物品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文