如何在Array中存储多个CheckboxLists? [英] How to store Multiple CheckboxLists in Array ?
本文介绍了如何在Array中存储多个CheckboxLists?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我正在开发一个小应用程序,它在1个网页中有13个CheckBoxLists,我试图在Array中存储这些控件但是我是新的对此,我没有得到如何完成这项任务。任何人都可以告诉我如何在数组中存储CheckBoxList控件或任何我可以使其可用于LOOP的替代品。
谢谢提前。
问候
Abdul Qayyum
Hello,
I am working on one small application which is have 13 CheckBoxLists in 1 webpage, I am trying to store those controls in Array but I am new to this, I am not getting how to accomplish this task. Can any one tell me how to store CheckBoxList control in Array or any alternate thing which I can make it available for LOOP.
Thanks in advance.
Regards
Abdul Qayyum
推荐答案
试试这个
try this
<asp:CheckBoxList runat="server" ID="YrChkBox" CssClass="question-wrapper" RepeatLayout="UnorderedList">
<asp:ListItem Value="1">SkyDrive</asp:ListItem>
<asp:ListItem Value="2">Google Drive</asp:ListItem>
<asp:ListItem Value="3">Own FTP server</asp:ListItem>
<asp:ListItem Value="4">Database (fx MongoDB)</asp:ListItem>
<asp:ListItem Value="5">Local on pc/mac</asp:ListItem>
</asp:CheckBoxList>
// Create the list to store.
List<String> YrStrList = new List<string>();
// Loop through each item.
foreach (ListItem item in YrChkBox.Items)
{
if (item.Selected)
{
// If the item is selected, add the value to the list.
YrStrList.Add(item.Value);
}
else
{
// Item is not selected, do something else.
}
}
很明显,复选框的集合应该用布尔数组来表示,但它有一个(可能不是非常关键的问题):它远没有内存效率。您可以轻松地将其压缩到一个位数组中而不会造成任何严重的性能损失,因为.NET FCL中已经提供了相应的集合: https://msdn.microsoft.com/en-us/library/system.collections.bitarray%28v=vs.110%29.aspx 一> [ ^ ]。
我无法想象填充UI(复选框集)和更新此数据数组的编码问题可能确实是个问题。
-SA
It looks obvious that the set of check boxes should be represented by a Boolean array, but it would have one (probably not very critical problem): it is far from being memory-efficient. You can easily squeeze it in an array of bits without any serious performance toll, because the appropriate collection is already available in .NET FCL: https://msdn.microsoft.com/en-us/library/system.collections.bitarray%28v=vs.110%29.aspx[^].
I cannot imagine that the coding problem of populating UI (set of check boxes) and updating this data array could really be a problem.
—SA
这篇关于如何在Array中存储多个CheckboxLists?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文