Click here to Skip to main content
15,607,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to use multipal values selected in checkboxlist in sql command

now i use
SqlCommand cmd = new SqlCommand("SELECT CustID,[P1],[P2] from temp1 up pivot(sum (quantity) for ProductID in (P1,P2) ) as pvt order by CustID",con);


but i want use Dynamic value of P1, P2 in sql command.

any one can help me,

thanks in advance.
Posted
Updated 16-Feb-15 21:09pm
v2
Comments
You mean that you want to pass some values for P1 and P2?
Shrikesh_kale 17-Feb-15 2:25am    
no i want to add P1,P2, P3 dynamic selection from the checkboxlist selected items.
checkboxlist contains P1 to P10
You previously mentioned that it is a Combobox. Now you are saying Checkboxlist. What have you tried for that?

1 solution

You ca add a javascript function to concate list box value like this

C#
function listBoxToString(listBox,all) {
    if (typeof listBox === "string") {
        listBox = document.getElementById(listBox);
    }
    if (!(listBox || listBox.options)) {
        throw Error("No options");
    }
    var options=[],opt;
    for (var i=0, l=listBox.options.length; i < l; ++i) {
        opt = listBox.options[i];
        if (all || opt.selected ) {
            options.push(opt.value);
        }
    }
    return options.join(",");
}



then You need to pass it to sql parameter
like @ListBoxValue , It should be string type.
after that you need to create a function to split this value or you can use IN Operator in sp login

like Select * from table
where id IN (@ListBoxValue)
 
Share this answer
 

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