473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

listbox items looping problem

dear all,
i have a listbox whose items are displayed in listbox e.g
('1','3','4',)
my problem is the last comma (, after 4) i don't want this comma as i
have to use
this string in sql query.
the loop through procedure is this

protected void Button1_Click1(object sender, EventArgs e)
{
string msg = "";

foreach (ListItem li in listboxcategory.Items)
{
if (li.Selected == true)
{
msg += "'" + li.Value + "'" + ",";
}
}
Label1.Text = "("+ msg + ")";
}

thanks in advance

Jun 19 '06 #1
2 1336
na********@yahoo.com wrote:
dear all,
i have a listbox whose items are displayed in listbox e.g
('1','3','4',)
my problem is the last comma (, after 4) i don't want this comma as i
have to use
this string in sql query.
the loop through procedure is this

protected void Button1_Click1(object sender, EventArgs e)
{
string msg = "";

foreach (ListItem li in listboxcategory.Items)
{
if (li.Selected == true)
{
msg += "'" + li.Value + "'" + ",";
}
}
Label1.Text = "("+ msg + ")";
}

thanks in advance

You can use substring on the variable msg after the loop to remove the
trailing comma.
Jun 19 '06 #2

Ray Booysen wrote:
na********@yahoo.com wrote:
dear all,
i have a listbox whose items are displayed in listbox e.g
('1','3','4',)
my problem is the last comma (, after 4) i don't want this comma as i
have to use
this string in sql query.
the loop through procedure is this

protected void Button1_Click1(object sender, EventArgs e)
{
string msg = "";

foreach (ListItem li in listboxcategory.Items)
{
if (li.Selected == true)
{
msg += "'" + li.Value + "'" + ",";
}
}
Label1.Text = "("+ msg + ")";
}

thanks in advance

You can use substring on the variable msg after the loop to remove the
trailing comma.


dear please give any code example using c#

Jun 19 '06 #3

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

Similar topics

1
by: bruce | last post by:
Hello, I have a small form that pops up when a user moves off the current record of a rather sizeable data entry form. The purpose of this form is to list warnings about various fields on the...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
3
by: VB Programmer | last post by:
Here's the code: For Each li As ListItem In Me.lstAssignedEmailAddresses.Items If li.Selected = True Then Me.lstAssignedEmailAddresses.Items.Remove(li) End If Next When I remove an item I get...
5
by: Chris Kettenbach | last post by:
Good morning, Does anyone happen to know if there's a way to make an array of the selected items in an asp:ListBox? I know you can loop through and check the selected property, my question is how...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
2
by: Greg | last post by:
I have a listbox inside of a DetailsView. There are three departments to choose from, Corporate, Group, Vacation. The listbox is set to SelectionMode="multiple". I think I have this loop setup...
4
by: straydawg | last post by:
Creating listbox for Role and initially populating with loop myDataTable = myDataSet.Tables(1) lbRole.Items.Clear() Dim dataRow_t As DataRow For Each dataRow_t In myDataTable.Rows...
2
by: rodchar | last post by:
hey all, i have a listbox on my .aspx page and when i highlight an item in the listbox should i just be able to loop thru the items collection of the listbox and delete what is selected? it's...
3
by: Robert W. | last post by:
I have a SQL Server table called "ClosedMonths" that contains two pertinent fields: Yearx Monthx 2000 1 2000 2 2000 3 I want to simply query this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.