Ticket Q235764
Visible to All Users

Passing Gridview Paging/Sorting/Grouping/Filtering expressions to business logic Select Methods

created 15 years ago

Hi guys,
I am in the process of evaluating the aspxGridView and i have to say its fantastic. However I have come across a situation and I am struggling to find a way through it. I do most of the paging, sorting, grouping and filtering at database level for maximum performance and overcoming memory issues. E.g. Paging at database level is done by passing gridview PageSize and first row index of the current page as parameters to the business logic methods, which in turn passes these two parameters to the data access provider method. The dataaccess provider method uses these two parameters (PageSize and StartRowIndex) to only retrieve the desired set of rows instead of returning all the rows from the database. So e.g. if there are millions of rows and the gridview page size is 10, instead of returning million rows in memory, only 10 rows are returned, keeping the server memory free.
I know aspxGridView is very fast and perform paging, sorting, grouping and filtering in seconds for thosands of rows but I still think its a better approach to perform all these functions at the database level.
So with the normal asp.net GridView, there is a way to automatically pass these two parameters to the business object method by setting the ObjectDataSource EnablePaging=true and defining SelectCountMethod. Most of my business objects method expects the PageSize and StartRowIndex parameters.
The above is not working with the AspxGridView & ObjectDataSource though. I receive values of 0 for both the parameters in my business logic methods. I am sure there must be a way to get hold of these values. Infact not just the page size and start row index, I would also like to know how to pass sort, filter and grouping expression to my business logic methods, so that I can do all this stuff at database level in my sql queries?
Awaiting
Nabeel Farid

Show previous comments (15)
DevExpress Support Team 15 years ago

    Hi Farid,
    The grid caches values for its cells. This cache is stored in a hidden field. We do not cache objects as it is possible that we won't be able to deserialize them from a string. The Select method is called, because you are asking the grid for a data object. If there is a value in the cache and you need it, the Select method is not called.
    >>
    In the standard asp.net grid, the underlying object can be retrieve by casting e.DataItem in the RowDataBound event, but RowDatabound event is raised only if the grid is bind
    <<
    Yes, you are right. Why do you need to obtain a row object when the ASPxGridView is not bound to the DataSource? If you need to know whether the grid was bound to the DataSource during the current request, handle the gridView's DataBound event.

    Thanks,
    Plato

      Thanks for your response. I think I need to explain you again what I am trying to achieve. There might be another way using aspxGridview.
      I am using aspxGridView with an ObjectDataSource that binds to a collection of custom objects(a list of Customer class objects). The customer class has two properties: Name and Address. The Address property is an object of type Address Class. Inside the grid I have a TemplateDataTextColumn in which I have an aspxLabel . The text property of the label is bind to the Customer class Name property. Now what i would like to do is to make the label forecolor green if the customer Address is not null and red if the Address is null.
      When using the standard asp.net gridview, I normally achieve this in the RowDataBound event casting e.DataItem to the customer object and then using e.Row.FindControl() to get the label and then finally checking if the custom objects' Address property is null or not and change the color of the label accordingly.
      I am trying to acheive the above with aspxGridView in HtmlRowCreated event and using e.FindRow() to get the Customer object. It works fine when the page loads for the first time. However if a postback occurs (anywhere on the page), HtmlRowCreated is raised again and e.FindRopw() results in Select method call, wasting memory and time. In standard asp.net grid, the RowDataBound event does not get raise for a postback, so no calls to select method is made.
      So Is there a way where i can achieve the above, without calls being made to select method on postback, just like standard asp.net grid? The calls to Select method for every postback is just not acceptable. May be I should not be doing this in HtmlRowCreated event? Is there another event? Should I do this in DataBound event ? How? Help please
      Awaiting,
      Nabeel

      DevExpress Support Team 15 years ago

        Hi Nabeel,
        Thank you for the explanation. I will try to create this project for you using the ASPxGridView. If you send me a GridView-based project, illustrating the desired functionality, this would be of great help.
        Thanks,
        Plato

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.