472,954 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

retrieve listbox values and make comma seperated

I need make a comma seperated list, but whwn I build the list I get a
comma at the end. How do I remove it?

foreach (ListItem lst in REIPropertyType.Items)
{
if (lst.Selected == true)
{
REIPropertyTypeVal += lst.ToString() + ",";
}

}

Jul 18 '06 #1
3 2957
I need make a comma seperated list, but whwn I build the list I get a
comma at the end. How do I remove it?
Hello,

Instead of a 'for-each' loop, you can use a regular 'for' loop and check
whether the iterator's value is less than the last item's index
(REIPropertyType.Items.Count???? - 1) and if so, append the comma:

for (int i = 0; i < REIPropertyType.Items.Count; i++)
{
ListItem lst = REIPropertyType.Items[i] as ListItem;
if (lst.Selected == true)
REIPropertyTypeVal += lst.ToString();
if (i < REIPropertyType.Items.Count - 1)
REIPropertyTypeVal += ",";
}

Hope this helps.
--
Best regards,

Stanimir Stoyanov
ad***@nospam.stoyanoff.info

Jul 18 '06 #2
Just remove it afterwards:
REIPropertyTypeVal = REIPropertyTypeVal.Remove(REIPropertyTypeVal.Lengt h -
1);
or
REIPropertyTypeVal = REIPropertyTypeVal.TrimEnd(',');

/claes

<df********@hotmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
>I need make a comma seperated list, but whwn I build the list I get a
comma at the end. How do I remove it?

foreach (ListItem lst in REIPropertyType.Items)
{
if (lst.Selected == true)
{
REIPropertyTypeVal += lst.ToString() + ",";
}

}

Jul 18 '06 #3
Note that the first would raise an ArgumentOutOfRangeException in the case
that there are no (selected) items in the ListBox control and thus
REIPropertyTypeVal is an empty string - trying to remove all characters after
the -1st position.
--
Best regards,

Stanimir Stoyanov
ad***@nospam.stoyanoff.info
"Claes Bergefall" wrote:
Just remove it afterwards:
REIPropertyTypeVal = REIPropertyTypeVal.Remove(REIPropertyTypeVal.Lengt h -
1);
or
REIPropertyTypeVal = REIPropertyTypeVal.TrimEnd(',');

/claes

<df********@hotmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
I need make a comma seperated list, but whwn I build the list I get a
comma at the end. How do I remove it?

foreach (ListItem lst in REIPropertyType.Items)
{
if (lst.Selected == true)
{
REIPropertyTypeVal += lst.ToString() + ",";
}

}


Jul 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: muzamil | last post by:
To get rid of redundant data in a table, my cleint will be providing something like this: IDtokeep Ids to delete 34 24,35,49 12 14,178,1457 54 32,65,68 I have to write a...
1
by: -rick | last post by:
I have a form which contains a multiple selection list box. How can I use the list box so that all items selected are added to the record of it's corresponding field in a table with each selected...
4
by: Henrik Holle | last post by:
Hi, i have a serverside listbox but i modify the value with javascript on the clientside. On postback my changed/added values are all lost? what am i doing wrong? Is it not possible to change...
4
by: Justin | last post by:
I have a web form that allow the user to add dates to a listbox control and they are also added to an arraylist at the same time but I do not know how to select all the rows into one string then...
6
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I...
3
by: tshad | last post by:
How do I get to the datatextfield of listbox? I can get the the datavaluefield using the selectedvalue. I want to get the text portion of the listbox that the user selected. Thanks, Tom
2
nehashri
by: nehashri | last post by:
i hv a database in access wid Asp as front end. ven given a word in search command(of the front end) it shud go to a table in which each field has words serated by comma. each word shud b checked...
4
by: kashif73 | last post by:
Hi, How can I populate my multi select LISTBOX from access database. The values are seperated by a comma in the column of table. I want the respective OPTIONS in listbox to be SELECTED, when read...
1
by: buterfly0707 | last post by:
hi.. i want to add selected multiple items form list box to text box(MultiLine) seperated with a comma in each item.I know how to add multiple list box values to another List box. but how can i...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.