C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Display all selected items in a CheckBox List as a single text


Posted Date: 16 May 2008    Resource Type: Code Snippets    Category: Web Access
Author: mohanMember Level: Silver    
Rating: Points: 10



Actually the situation is there are 3 or more items in checkbox list.For example the items are as displayed below.

1. 1 room
2. 2 room
3. 3 room & so on

Now if we select 2&3 items we get 2 room&3 room. but the output should be 2 & 3 room. I suggest a way for this is as follows:


//First add System.Collections NameSpace inorder to get ArrayList
ArrayList arr = new ArrayList();
//Specify the word which u want to trim.
string trim = "room";
//Loop to rotate through all the items in checkboxlist.
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
//To know which item is selected.
if(CheckBoxList1.Items[i].Selected)
{
//Adding the selected items to arraylist by trimming the 'trim' string
arr.Add(CheckBoxList1.Items[i].Text.Trim(trim.ToCharArray()));
}
}
//A new Array is created.
string[] str=new string[arr.Count];
//Items in arraylist is copied into new array inorder to use join method
arr.CopyTo(str);
//Finally to get Desired Output we are adding '&' between items in array & 'trim' string.
string final= string.Join("&",str)+trim;




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Get Proxy Server address from Internet Explorer
Previous Resource: SAT Online Radio
Return to Discussion Resource Index
Post New Resource
Category: Web Access


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use