Sunday, February 19, 2012

<SelectParameters> & checked items from CheckBoxList

Column1 in table 1 has a range from 1 to 5 (int)

A CheckboxList displays these 5 items. When checked (for example 1 and 4) I want a gridview with sqldatasource=sqlProducts to display the records where column1 values 1 or 4.

When I use the code below I only get the records where column1 values 1...

<asp:SQLDataSource id="sqlProducts" Runat="Server" SelectCommand="Select * From Table1 where Column1 IN (@.CBLchecked_items)" ConnectionString="<%$ ConnectionStrings:pubs %>">
<SelectParameters>
<asp:ControlParameter Name="CBLchecked_items" ControlID="CBL" propertyname="SelectedValue" type="String" />
</SelectParameters>
</asp:SQLDataSource>

Hi~

SelectedValue returns the first selected value .

You can iterate to get all selected values:

For i = 0To Check1.Items.Count - 1If Check1.Items(i).SelectedThen' List the selected items s = s & Check1.Items(i).Text s = s &","End If Next
Hope it helps.|||

I got the problem to get the checked item in CheckBoxList here is the code :

foreach (ListItem itemin cblRoles.Items){if (item.Selected)// here the item.Selected always = false {// do something } }
 

No comments:

Post a Comment