This is a migrated thread and some comments may be shown as answers.

RADGrid value filter by listbox

5 Answers 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 06 Jan 2009, 08:26 AM
hi

How do i show grid value based on select value from a listbox? I am using a stored procedures:

Create PROCEDURE [dbo].[spByInfoID]
@ID varchar(500)
AS
BEGIN
SET NOCOUNT ON;
SELECT * from tblInfo
WHERE  ',' + @ID + ',' LIKE '%,' + CAST(infoID AS varchar(10)) + ',%'

I configured radgrid as SQLDatasource using this stored procedures and parameter source is Control and the Control id is a listbox. No default value.

I may have done it the wrong way. But do enlighten me. Thanks

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Jan 2009, 09:49 AM
Hi L,

I have implemented the desired scenario as shown below. Here I have bound the Grid with two fields and set those fields as the DataTextField and DataValueField for the ListBox. The StoredProcedure is receiving infoID  from the ListBox.

ASPX:
 
   <telerik:RadGrid ID="RadGrid1" runat="server"    AutoGenerateColumns="false"   DataSourceID="SqlDataSource2"    > 
            <MasterTableView   Name="RadGrid1"  CommandItemDisplay="Top"  DataSourceID="SqlDataSource2" > 
 
           <Columns> 
             <telerik:GridBoundColumn DataField="infoID " UniqueName="infoID " HeaderText="ID" ></telerik:GridBoundColumn> 
             <telerik:GridBoundColumn DataField="LargeString" UniqueName="LargeString" HeaderText="LargeString" ></telerik:GridBoundColumn> 
             
          </Columns> 
         
      </MasterTableView> 
    </telerik:RadGrid> 
 
        <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" 
            DataTextField="LargeString" DataValueField="infoID "></asp:ListBox> 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestDbConnectionString %>" 
            SelectCommand="SELECT * FROM [tblInfo]"></asp:SqlDataSource> 
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TestDbConnectionString %>" 
            SelectCommand="spByInfoID" SelectCommandType="StoredProcedure"
            <SelectParameters> 
                <asp:ControlParameter ControlID="ListBox1" Name="ID" PropertyName="SelectedValue" 
                    Type="String" /> 
            </SelectParameters> 
        </asp:SqlDataSource> 
 
 

StoredProcedure:
alter PROCEDURE [dbo].[spByInfoID] 
@ID varchar(500) 
AS 
BEGIN 
SET NOCOUNT ON
SELECT * from tblInfo 
WHERE  ',' + @ID + ',' LIKE '%,' + CAST(infoID AS varchar(10)) + ',%'  
 
END  

Hope this helps..
Princy
0
L
Top achievements
Rank 1
answered on 06 Jan 2009, 01:45 PM
hi

Sorry if i asked too much. How do i implement this with a click of a button? Meaning i now select some items from the listbox and do a click of a button.

It seems that now is the postback of the listbox.

Thanks
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Jan 2009, 04:41 AM
Hi L,

The above code performs the operation with the AutoPostBack property of the ListBox. For achieving the desired scenario you just need to set the AutoPostBack property of the ListBox to false and then clicking a button will cause a PostBack which will perform the operation.

Regards
Shinu
0
L
Top achievements
Rank 1
answered on 13 Jan 2009, 06:02 AM
hi

I have noticed from your given code that the listbox's selectionMode is not multi. But my listbox selecetionMode is Multi.

And when i  tried selecting multi value it doesn't produce the desire result. thanks
0
Accepted
Yavor
Telerik team
answered on 13 Jan 2009, 06:31 AM
Hello L,

In this case, you need to alter the select statement to include "AND"/"OR" clauses, which would allow you to include the other values from the listBox.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
L
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
L
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Yavor
Telerik team
Share this question
or