How do we prevent data binding form occuring in PageLoad and, here's the catch, still get the RadGrid to display including the filters, which we use as a search form? Something like:
if (e.RebindReason != GridRebindReason.InitialLoad)
((RadGrid)sender).DataSource = new object[] { };
Will prevent the data binding, but it will also prevent the user from ever doing a real search :)
if (e.RebindReason != GridRebindReason.InitialLoad)
((RadGrid)sender).DataSource = new object[] { };
Will prevent the data binding, but it will also prevent the user from ever doing a real search :)
9 Answers, 1 is accepted
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 07 Feb 2011, 04:53 PM
Can answer my own question, to help others who may face the same problem. Basically, what we did was to create an empty "resultset" from the Business Layer, and bound to that:
(Please note that we are using Entity Framework thus working with real objects, BookTransaction is an entity).
if (e.RebindReason == GridRebindReason.InitialLoad)
((RadGrid)sender).DataSource = new List<
BookTransaction
>[] { };
else
{
((RadGrid)sender).DataSource = eodsObjectDataSourceBookTransaction;
}
(Please note that we are using Entity Framework thus working with real objects, BookTransaction is an entity).
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 10 Feb 2011, 11:40 AM
Turns out this affected updates/inserts also (for obvious reasons). Is there a way to prevent databind at PageLoad(), but still be able to use automatic dataoperations etc as you would normally do? The only thing we want to do is to prevent the RadGrid from binding at PageLoad(), but still be displayed as the searchform is implemented as filters in the grid, but the rest should be the same.
I know you can use the RadGrid1_UpdateCommand but that solution I feel is a bit to complicated and hard to maintain, and it doesn't work to well using Entity Framework (where objects are used). I guess you would be forced to use statements like
MyObject.MyProperty = updatedValues.myNewValue
which is hard to maintain over time.
I know you can use the RadGrid1_UpdateCommand but that solution I feel is a bit to complicated and hard to maintain, and it doesn't work to well using Entity Framework (where objects are used). I guess you would be forced to use statements like
MyObject.MyProperty = updatedValues.myNewValue
which is hard to maintain over time.
0
Hello Patrik,
Yes, the approach from your last post should do the trick for you.
Best wishes,
Nikolay
the Telerik team
Yes, the approach from your last post should do the trick for you.
Best wishes,
Nikolay
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.
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 11 Feb 2011, 02:46 AM
Yes, it will, but when wokring with objects, it will force you to use reflection to be able to fill the object properties with the values from the EditForm, which is a bit complex.
An alternative solution, which perhaps isn't the prettiest, but should be easier to maintain, would be to have a filterExpression that would make sure you got no hits, which would result in an empty RadGrid (even though it would do a roundtrip to the database). In our case, we actually export the filterExpression in LINQ to the Business Layer, so this roundtrip wouldn't be to coslty (no rows would be sent from the database). Telerik, what would be the best method of implementing such a solution? I guess what we are talking about would be some kind of default filterExpression which would only last the first databind (PageLoad), which is then replaced with "real" filterExpressions as the search form/filter form is used (which should be handled by itself, stanard procedure).
An alternative solution, which perhaps isn't the prettiest, but should be easier to maintain, would be to have a filterExpression that would make sure you got no hits, which would result in an empty RadGrid (even though it would do a roundtrip to the database). In our case, we actually export the filterExpression in LINQ to the Business Layer, so this roundtrip wouldn't be to coslty (no rows would be sent from the database). Telerik, what would be the best method of implementing such a solution? I guess what we are talking about would be some kind of default filterExpression which would only last the first databind (PageLoad), which is then replaced with "real" filterExpressions as the search form/filter form is used (which should be handled by itself, stanard procedure).
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 11 Feb 2011, 01:03 PM
We experimented a bit with filterExpressions by simply setting it to "false" by default:
FilterExpression="false"
and this seem to work quite well, and is a solution much easier to maintain we think. In our case, we export the LINQ filterExpression to our BusinessLayer and DataLayer, so we won't actually fetch any unnecessary data, but I guess it could be used by anyone wanting to have an empty grid on pageload no matter what, if you are prepared to do the databind and load data, even though it wont be displayed by the RadGrid.
FilterExpression="false"
and this seem to work quite well, and is a solution much easier to maintain we think. In our case, we export the LINQ filterExpression to our BusinessLayer and DataLayer, so we won't actually fetch any unnecessary data, but I guess it could be used by anyone wanting to have an empty grid on pageload no matter what, if you are prepared to do the databind and load data, even though it wont be displayed by the RadGrid.
0
Hello Patrik,
You will need at least binding to empty collection in order RadGrid to render it's structure.
Best wishes,
Nikolay
the Telerik team
You will need at least binding to empty collection in order RadGrid to render it's structure.
Best wishes,
Nikolay
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.
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 16 Feb 2011, 06:05 PM
Nikolay, what is this latest replyan answer to? I mean, isn't it a repeate of what was written in the second reply above? :)
0
Hello Patrik,
Yes it is repeated with the statement in the second reply.
Nikolay
the Telerik team
Yes it is repeated with the statement in the second reply.
Nikolay
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Suresh
Top achievements
Rank 1
answered on 26 Oct 2017, 01:23 PM
Hello All and Telerik Admin,
I have tried one trick that is... I added an "if condition" of Page.IsPostback
If page is postback, I let the "OnNeedDataSource" code run else nothing.. And it seems working...
Could you please confirm if this approach is good to go with?