Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code is

C#
String selectedvalue = "";
            int count = 0;
             sSQL = "SELECT DISTINCT(EM_MobileNo) FROM ps.employee_master ";

             foreach (ListItem li in ListBox2.Items )
             {
                 if (li.Selected)
                 {
                     selectedvalue +=",'"+li.Value+"'";
                 }
                 else
                     count++;
                 selectedvalue += "'"+li.Value+"'";
             }
                   sSQL = sSQL + " WHERE EM_Department like '" + ddDepartment.SelectedValue.ToString() + "'";
                   sSQL = sSQL + " AND EM_SerialNo IN ('" + selectedvalue  + "')";


Please suggest me about this , in my code,while dubugging, if(li.selected) is false even there is an items in listbox
Posted
Updated 28-Nov-13 18:33pm
v2
Comments
Suvabrata Roy 29-Nov-13 0:17am    
I did not understand your problem...
SVT02 29-Nov-13 0:42am    
my code overwrite the selectedvalue thats why it selects only one item rather than all items, so sms can be send to single person,but i want to send it to all persons(items) of listbox....any suggession?
santhosh-padamatinti 29-Nov-13 1:08am    
Fetching the mobile numbers part seems correct, you will able to get the all selected mobile number from the above code, Where you are getting exact problem ?
SVT02 29-Nov-13 1:27am    
Actual problem is that it selects only one mobile number, not all

1 solution

It seems your dynamic sql prepartion is worng, Try with below block


C#
String selectedvalue = "";
int count = 0;
sSQL = "SELECT DISTINCT(EM_MobileNo) FROM ps.employee_master ";

foreach (ListItem li in ListBox1.Items)
{

    if (li.Selected)
    {
        if (string.IsNullOrEmpty(selectedvalue))
        {
            selectedvalue = li.Value + "'";
        }
        else
        {
            selectedvalue += ",'" + li.Value + "'";
        }

    }

}
sSQL = sSQL + " WHERE EM_Department like '" + ddDepartment.SelectedValue.ToString() + "'";
sSQL = sSQL + " AND EM_SerialNo IN ('" + selectedvalue + ")";
 
Share this answer
 
Comments
SVT02 29-Nov-13 2:40am    
Its run, thank you santhosh very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900