如何设置在asp.net中的CheckBoxList多个选择的值 [英] How to set multiple selected values in asp.net checkboxlist

查看:603
本文介绍了如何设置在asp.net中的CheckBoxList多个选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有绑定到LINQ to SQL的数据源一个asp.net复选框列表,当我检查我的CheckBoxList在页面加载事件的项目数为0。我希望能够在我的CheckBoxList设置选定的项目在这里,但不能。

I have a asp.net checkbox list bound to a linq to sql datasource and when I check the item count of my CheckBoxList on the page load event it is 0. I want to be able to set the selected items on my checkboxlist here but cannot.

数据源的后页面加载所选的事件触发。如果是这样的话,我怎么可以设置选定的项目我的名单上?

The datasource's selected event fires after the page load. If this is the case, how can I set the selected items on my list?

如果我设置的SelectedValue的值只显示为选择的所有这些选择的值,而不是最后一个值。我怎么可以在我的页面加载事件的CheckBoxList选择多个值?

If I set the SelectedValue to a value it only displays the last value as selected instead of all the values which are selected. How can I select multiple values in my checkboxlist in the pageload event?

推荐答案

我知道这是旧的文章,但我有同样的问题最近。

I know this is an old post but I had the same problem recently.

要选择一个数据绑定的CheckBoxList多个项目,处理过的项目收集的数据绑定事件和循环单独设置Selected属性上按要求每一个项目。

To select multiple items of a DataBound CheckBoxList, handle the DataBound event and loop through the Items collection setting the Selected property individually on each item as required.

设置控件的SelectedValue属性只检查最后一项。

Setting the SelectedValue property of the control only checks the final item.

 foreach (ListItem item in MyCheckBoxList.Items)
 {
     item.Selected = ShouldItemBeSelectedMethod(item.Value);
 }

这篇关于如何设置在asp.net中的CheckBoxList多个选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆