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

RadGrid doubts - How it works (datasource, select and filter)

1 Answer 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simó
Top achievements
Rank 1
Simó asked on 10 Aug 2011, 08:33 AM
Hi Developer,
first I apologize for my english (it's not very good).  I'am a beginner with telerik, and I have some doubts with the RadGrid.

Actually I develop a WebApplication that uses Telerik Asp.Net ajax controls, exactly a I develop with the RadGridControl.
I like to read from a table (from database) and use a radgrid to show results from "query" (after I'll improve the example app to include "buttons" to do action like detail view, master/detail, etc).
Note: The table to read will have more record (actually has about 10.000)

I am trying to scenarios

a) RadGrid with SqlDatasource (and filtering)

In this case, I define a radgrid (radGrid1) which uses a SqlDatasource (sqlDatasource) only with SelectCommand ("select * from mytable")

In this case, I define a SqlDatasource, with a SelectCommand "select * from mytable"

# MyTableViewScenarioA.aspx

...
<!-- RadGrid  -->
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"
    AllowSorting="True" CellSpacing="0" DataSourceID="SqlDataSource1"
    GridLines="None" PageSize="30">
...

<!-- SqlDatasource -->
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="connectionstring"
    
        SelectCommand="SELECT * from MyTable"></asp:SqlDataSource>

# MyTableViewScenarioA.aspx.cs


b) RadGrid with ObjectDatasource (and filtering)

In this case, I define a RadGrid (radGrid1) without datasource. And before I use the NeedDatasource method to set the radgrid1's datasource with a list. The list is get from a method of a service class that query database (this method creates a select query and return a list of a type object)

# MyTableService.cs
public class MyTableService
{
    public List<MyTable> Find(Dicctionary<string, object> parameters)
    {
        // List<MyTable> = "select * from mytable where ..."
    }

   .....
}

# MyTableViewScenarioB.aspx

...
<telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="True"
        AllowSorting="True" PageSize="15"
        AutoGenerateColumns="False" CellSpacing="0" GridLines="None"
        onneeddatasource="RadGrid2_NeedDataSource" Skin="Windows7">

...

# MyTableViewScenarioB.aspx.cs

....
protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {

            MyTableService service = new MyTableService();

            Dictionary<string, object> parameters= new Dictionary<string, object>(5);

            DateTime datetimeTo = DateTime.Now;
            //DateTime datetimeFrom= datetimeTo .AddDays(-7);
            DateTime datetimeFrom= datetimeTo .AddDays(-45);

            parameters.Add("datetimeFrom", datetimeFrom);
            parameters.Add("datetimeTo ", datetimeTo );

            List<MyTable> myTableList = service .Find(parameters);

            this.RadGrid1.DataSource = myTableList ;
            //this.RadGrid1.DataBind();            
        }        
    }

...

I debug the application and I have some questions about radgrid

Q1) ¿Select is execute everty time when I click a "next page" ?
Note: In scenario B the answer is yes

Q2) If Q1 answer if yes considering scenario a). How I can optimize this?
If every time radgrid execute a select, the database return a big number of rows, but the grid limit the result considering page size.

Q3) If Q1 answer if no (considering scenario b). ¿Where is save the datasource?

Q4) In scenarioB. How I can use the values of the filter, in NeedDatasource, to create the dicctionary parametres use in Find method?
Note: asume that table "myTable" has four columns: column1 (int), column2 (string), colum3(number), colum4 (datetime)

Q5) How works radgrid filtering? When is applied the filter?
I like to know how works filterir, and when is applied.  In scenarioa is launch select command and before is aplied the filter or first is aplied the filter (to select query) and second is launch the query.
In first aproach, the select return all rows from database and after, dataset is filter. In second aproach, the database return the "correct" rows that match with the filter.

Q6) When I change a filter, radgrid reload the page. It's possible to avoid this feature?
I like to use a command button "Apply filters" similar to a tipical search form. The idea is to avoid reload the grid every time that a filter change (and avoid to query the database everty time)

Q7) There is a event to inform me that a filter have been change?
Note: this is importan if i use scenarioB. The idea is recalculate de parameters, every time a user change a filter.

Q8) If I use scenarioB, it's possible to save the list in the view state?
The idea, is use the save list every time that the user click on a specific page (in this case, this is no query in database). If the user change a filter, then, the list (datasource) should be recalculated.

Q7) Which of two scenarios is better to use ASP Net Ajax controls?
ScenarioA is the typical of the telerik examples. ScenarioB is  typical of a orm application (entity framework, nhibernate, etc) where the develop use bussines object indepent of database (and is desgined to use, for exampe with a mvc application. In this case, the search view constains a model that consist in a list<MyTable>)

Thank you so much for your help. Sorry for my english.
Regards.

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 12 Aug 2011, 09:15 AM
Hello Simó,

Our system indicates that you have opened a support ticket concerning the same issues. In order to avoid duplicate posts,
I suggest that we continue the communication in the support ticket.

All the best,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Simó
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or