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

RadGrid filter templates

3 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 04 Jan 2013, 10:13 AM

Hello,

First, I wish you a happy new year ! :-)

Secondly, I am trying to include in the code of my RadGrid the filter template which is being shown here :  http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx

But it seems that to fill the DropDown boxes , you are accessing  the database each time by defining SqlDataSource objects (for example SqlDataSource1 in the code sample :

<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
       ProviderName="System.Data.SqlClient" SelectCommand="SELECT CustomerID, ContactName, ContactTitle, City, Country, Bool FROM Customers"
       runat="server"></asp:SqlDataSource>


What I want is to have in each dropdown box only the values that really appear into the corresponding RadGrid column (data from RadGrid datasource) and not all the available values from the database. For example, if I only have 3 different records in the grid, I just want to have the three corresponding values in my drop down boxes.

So can an you tell me how to define my DataSource for all DropDonwn boxes to achieve that ?I have been looking at ObjectDataSource but it seems that by using SqlDataSource or ObjectDataSource, il will always have to send an SQL request to the database. That's exactly what I want to avoid, as I already used an SQL request to retrieve the data when populating the RadGrid ...

 Thank you for your help.

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 08 Jan 2013, 09:35 AM
Hello Bruno,

Happy New Year.

You can use the DISTINCT sql operator as demonstrated in the mentioned demo. For instance, SqlDataSource4 is used to bind the unique values of the countries:
<asp:SqlDataSource ID="SqlDataSource4" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT Country FROM Customers"
runat="server"></asp:SqlDataSource>

That should do the trick. Please give it a try and let me know if it works for you.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Bruno
Top achievements
Rank 1
answered on 08 Jan 2013, 10:46 AM

Hello,

Thank you for the answer, but I think you did not understand my concern.

I do not want to have all distinct countries (in your example) from the database, but only the countries which appear in the RadGrid column.

For example, I could have 200 distinct countries in my database table, but only 2 records displayed in the RadGrid, with 2 distinct countries (for example France and USA). So I only want to have these two countries (France and USA) in the DropDown.
We could say it's a contextual dropdown, which is set according to the values displayed into the corresponding column.

Can you tell me how to achieve this ?

(If I use the DISTINCT operator as you suggested, I would have all 200 countries of my database in the DropDown, which is absolutely not the result I want to obtain.)

Thank you.

0
Eyup
Telerik team
answered on 11 Jan 2013, 06:52 AM
Hello Bruno,

The mentioned demo works in the exact requested manner. To verify that please select Sales Agent from Contact Title combo and you will notice that Country combo will contain only the remaining countries. You can check the RefreshCombos method in the code-behind file to see how this is achieved.

I hope this will prove helpful. Give it a try and let me know about the result.

Greetings,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Bruno
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Bruno
Top achievements
Rank 1
Share this question
or