none
EntityDataSource Filter with Gridview and DropDownList Controls RRS feed

  • Question

  • What is the best way to filter the data in a gridview (populated by an entitydatasource control) using the results of a dropdownlist? I've read numerous books and spent too many hours on forums researching this and have found that there are numerous ways in which this can be implemented.

    It seems that the most common approach is to use whereparameters and bind to the dropdownlist. However, when this solution is employed the filter is always active (there is no way to view unfiltered data - that I can find). I've also looked into implementing this behavior in the code behind. The solution here appears be centered on trapping on numerous events (selectedindexchanged, for example. However, I fear this solution may be pinging the database too frequently.

    Any suggestions and comments are greatly appreciated. Thanks!

    Wednesday, August 10, 2011 3:42 AM

Answers

All replies

  • Tagging along for ride.

    I do unconventional technique because I can't quit figure out the relationships between CollectionViewSource, CollectionViews and the result of an IEnumerable<type> result of a Linq query. 

    So, if you can get your items as a type of IEnumerable<type> from the DataGrid, you can run a LINQ query like this.

    var stuff = from GridViewItems.OfType(something).where(p=>p.property == cd.selectedItem.ToString();
    

    Unfortunately it doesn't maintain the list.


    JP
    Wednesday, August 10, 2011 4:00 AM
  • Hello,

    I suggest you can provide more detailed code snippets in your reply to help us analyze your question better. Regarding the performance of LINQ to SQL, I suggest you can check the following blogs for more detailed information. I think it will help you enlarge your experience.

    http://www.sidarok.com/web/blog/content/2008/05/02/10-tips-to-improve-your-linq-to-sql-application-performance.html

    http://www.codeproject.com/KB/cs/linqsql.aspx

    Thanks,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 12, 2011 11:07 AM
  • I don't really have any code snippets to provide.  I'm looking for input on the best way to write the code.  I am aware of the numerous options that exist (and I'm quite capable of implementing all of them).  However, my question is whether or not there is a preferred way to filter the data being displayed on a gridview control.  
    Monday, August 22, 2011 3:18 PM
  • Hello oufan222,

    Regarding handling large data, I suggest you can check Sorting and Paging (EntityDataSource) tech for more information. http://msdn.microsoft.com/en-us/library/cc488534.aspx

    In addtion, as you mentioned, you would like to display unfiltered data in DataGridView or other controls. AFAIK, we have to define the filter condition by ourselves. Perhaps, you can create another DataGridView which dedicated on displaying unfiltered data. Based on my experience, I suggest you can collect these data into memory and this made the performance or save the time to bind data into UI layer.

    Hope this helps.

    Thanks,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 23, 2011 2:18 AM