Reputation: 553
I want to create a sql query based on the selected Item from checkboxlist. Just want to remove last comma from the code below.
String queryt=" And Brand IN(";
foreach (ListItem lst in brandcklist.Items)
{
if (lst.Selected == true)
{
queryt += "'"+lst.Text+"',";
}
}
queryt += ")";
Label3.Text = queryt;
output for this is
And Brand IN('BlackBerry','Karbonn',)
note the comma after karbonn, I don't want to add comma after last item.
Upvotes: 0
Views: 748
Reputation: 2387
Just replace this line
queryt += ")";
with
queryt=queryt.TrimEnd(',') +")";
Upvotes: 1