Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > listbox items looping problem

Reply
Thread Tools

listbox items looping problem

 
 
nasirmajor@yahoo.com
Guest
Posts: n/a
 
      06-19-2006
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

 
Reply With Quote
 
 
 
 
Ray Booysen
Guest
Posts: n/a
 
      06-19-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.
 
Reply With Quote
 
 
 
 
nasirmajor@yahoo.com
Guest
Posts: n/a
 
      06-19-2006

Ray Booysen wrote:
> (E-Mail Removed) 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#

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy ListBox items to anoher listbox Tomas ASP .Net 1 08-12-2008 08:22 AM
Listbox move multiple selected items to second listbox K B ASP .Net 2 01-08-2007 11:16 AM
Get selected items from a Multi-Select Listbox without looping through all amypower@gmail.com Javascript 0 01-03-2007 03:47 PM
Looping through CheckBoxList items doesn't pick up selected ones when items were disabled Bart Van Hemelen ASP .Net 2 09-04-2006 08:35 AM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM



Advertisments