i am using sql datasource and a checkboxlist to filter a datalistview. i want to make a parameter for sqldatasource from code behind and use SQL IN to filter datalistview rows. when i check 1 checkbox in checkboxlist everything work great... but when i check more than 1 checkbox datalist view takes no data. this is my onselecting code for sql datasource:
protected void DS_subgroupID_changed_Selecting(object sender,SqlDataSourceSelectingEventArgs e)
{
List<String> selected = new List<String>();
foreach (ListItem item in CheckBoxList_subgroup.Items)
if (item.Selected)
{
selected.Add(item.Value);
}
String commaselect = String.Join(",", selected.ToArray());
e.Command.Parameters["@product_subgroup"].Value = commaselect;
}
and here is my sqldatasource control:
<asp:SqlDataSource ID="DS_subgroupID_changed" runat="server"
ConnectionString="<%$ ConnectionStrings:nimrokhDBConnectionString %>"
SelectCommand="SELECT * FROM [tbl_product] WHERE (([product_group] = @product_group) AND ([product_subgroup] IN (@product_subgroup)))"
OnSelecting="DS_subgroupID_changed_Selecting">
<SelectParameters>
<asp:ControlParameter ControlID="radio_list_group" Name="product_group" PropertyName="SelectedValue" Type="String" />
<asp:Parameter Name="product_subgroup" />
</SelectParameters>
</asp:SqlDataSource>
i have 1 table subgroup that contains subgroupID as int and subgroupname, and i have a table product that contan subgroup to store subgroup ID but this is in nvarchar. i wonder if this cause the problem. because my checkboxlist value is set to subgroupID form subgroup table.
i appretiate any help. thank you guys.