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

[Solved] Dont show data received onneeddatasource event

4 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jorge
Top achievements
Rank 1
Jorge asked on 19 May 2013, 01:55 AM
Hello,

I need to accomplish a curious behavior, i want that the event OnNeedDataSource look for the data but dont show it inside the radgrid, i need to query the data just using the radgrid filters, something like these steps:

1) User opens the page
2) Radgrids looks for the data but renders an empty grid (data keeps in memory)
3) user use the grid filters to query data
4) radgrid look for the data in memory to display the matched elements.

The radgrid is actually implemented to show the data at page load, so i will appreaciate if exists a low-effort way to accomplish this.

Thank you.

4 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 23 May 2013, 05:46 AM
Hi,

If there is not data in RadGrid how the user will know that he needs to filter the empty Grid in order to view the results?

Other than that you could set an empty datasource to RadGrid the first time and check if there is a filter expression applied to RadGrid to pass the datasource you want.

Regards,
Andrey
Telerik
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
Jorge
Top achievements
Rank 1
answered on 23 May 2013, 04:22 PM
Hello Andrey,

Could you give me an example about how to switch between the empty data source and the filled? if there is a filter applied search and if the filter expression is empty.. back to the empty datasource.
0
Andrey
Telerik team
answered on 28 May 2013, 11:17 AM
Hello,

Yes, this is a pseudo code how your NeedDataSource event should look:

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid grid = sender as RadGrid;
    if (grid.MasterTableView.FilterExpression != "")
    {
        //query the datasource using the filter expression
    }
    else
    {
        grid.DataSource = "";
    }
}


Regards,
Andrey
Telerik
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
Princy
Top achievements
Rank 2
answered on 28 May 2013, 12:24 PM
Hello Jorge,

Please try this code ,and check if this helps you.Here at first the FilterExpression is empty during page load,that condition is checked to set radgrid empty.

C#:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        if (RadGrid1.MasterTableView.FilterExpression == "")//Checks if the filter expression is empty
        {
            RadGrid1.DataSource = new int[] { };
        }
        else
        {
           //Bind the table to Radgrid1
            string selectQuery1 = "SELECT top 10 * FROM [Orders]";
            SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
            conn.Open();
            adapter1.Fill(dt1);
            conn.Close();
            RadGrid1.DataSource = dt1;
        }           
    }

Thanks,
Princy
Tags
Grid
Asked by
Jorge
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Jorge
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or