Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 25-Jun-15 19:24pm
v2

try this

XML
<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>




C++
// 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.
           }
       }
 
Share this answer
 
v3
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
 
Share this answer
 
Comments
CPallini 26-Jun-15 2:38am    
"I cannot imagine that the coding problem of populating UI (set of check boxes) and updating this data array could really be a problem."
Neither I, 5.
Sergey Alexandrovich Kryukov 26-Jun-15 8:33am    
Thank you, Carlo. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900