I would like to bind to comma delimited value's in WebDropDown to a SQL Server In Clause. What's the best way to do this? Here's some code.
<ig:WebDropDown ID="WebDropDown1" runat="server" EnableClosingDropDownOnSelect="false" EnableMultipleSelection="True" EnableCustomValues="False" EnableCustomValueSelection="False" > <Items> <ig:DropDownItem Selected="False" Text="Other" Value="''"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="Apple" Value="'Apple'"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="Orange" Value="'Orange'"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="Banana and Plantain" Value="'Banana',''Plantain'"> </ig:DropDownItem> </Items> </ig:WebDropDown>
Hard query like this <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DBNameConnectionString2 %>" SelectCommand="SELECT * FROM DBName.dbo.TableName WHERE ColumnFruit IN ('','Apple','Orange', 'Banana',''Plantain') </asp:SqlDataSource>Paramaterized like this <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DBNameConnectionString2 %>" SelectCommand="SELECT * FROM DBName.dbo.TableName WHERE ColumnFruit IN (@FruitCol) <SelectParameters> <%--<asp:ControlParameter ControlID="WebDropDown1" Name="FruitCol" PropertyName="SelectedItems.Value" />--%> </SelectParameters> </asp:SqlDataSource>
Something like this could create the string properly
protected string GetSelectedValue(Infragistics.Web.UI.ListControls.WebDropDown wdd) { char[] c = new char[] { ',' }; string s = string.Empty; for (int i = 0; i < wdd.SelectedItems.Count; i++) { s += wdd.SelectedItems[i].Value + ","; } return s.TrimEnd(c); }
Thanks for the help.
Hello air1kdf ,
I am just checking have you been able to resolve your issue?
I have been looking into your question and I could suggest you add these parameters in code behind as suggested here:
http://forums.asp.net/t/1145379.aspx/1
Please let me know if this helps.