in

CodeSmith Community

Your Code. Your Way. Faster!

EntityGridView CustomProc from View adds a null record

Last post 06-11-2008 10:13 PM by Xcalibur. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 05-17-2007 12:25 PM

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    EntityGridView CustomProc from View adds a null record

    I am confused why this code is in the EntityGridView.  Can anyone explain why this is necessary?  The result is that it adds a new entity to the list when I call my custom proc that returns no records.  I don't see this with methods that return a TList, but for whatever reason, it happens with a VList.  I can't think of any scenario where I would want to add a blank entity to my list after returning no results.  Can anyone shed some light on this?

            /// <summary>
            /// Retrieves data from the underlying data storage by calling the method that is identified by the
            /// SelectMethod property with the parameters in the SelectParameters collection.      
            /// </summary>
            /// <remarks>
            /// Occurs when a Select operation has completed.
            /// </remarks>
            void dsc_Selected(object sender, ObjectDataSourceStatusEventArgs e)
            {           
                if (e.AffectedRows == 0)
                {
                    // check if gridview bound to typed object data source
                    if (sender is Web.Data.IListDataSource)
                    {
                        // get the types of the generic type arguments
                        Type[] typeArguments = ((DataSourceControl)sender).GetType().BaseType.GetGenericArguments();

                        // create empty business object
                        object entity = EntityUtil.GetNewEntity(EntityUtil.GetType(typeArguments[0].FullName));
                       
                        // add empty object to the collection -- I COMMENTED OUT THE NEXT LINE
                        //EntityUtil.Add(e.ReturnValue as System.Collections.IList, entity);
                    }
                }
                RecordsCount = e.AffectedRows;
            }

    • Post Points: 60
  • 05-17-2007 1:57 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 723
    • Points 16,775

    Re: EntityGridView CustomProc from View adds a null record

    basolutions,

    By default GridView doesn't display column headers whenever no records returned from underline datasource, adding an empty object is a workaround. Based on your report you get empty row when return type is VList?

    Mike Shatny
    -------------------------------------
    Member of the .netTiers team
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 85
  • 05-17-2007 5:28 PM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: EntityGridView CustomProc from View adds a null record

    Thats correct, I get an empty row in my grid, which is confusing to the users, and only with a VList, I believe.  I have set the <EmptyDataTemplate> to display what I want when there is no data.  I think it would best suit everyone that a property be added to the datasource that gives the developer the option of adding this record if so neccesary instead of hacking this record into the datasource.

     Just my $.02 worth. 

     Thanks,

     Jesse

    • Post Points: 30
  • 05-18-2007 10:13 AM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: EntityGridView CustomProc from View adds a null record

    Ok, that did it for me... I finallly got motivated enough to create a patch to fix the automatic adding of a empty business object to the IList when its null and changing hyperlinks to text when exporting.

    In this patch, I have created a new property called InsertRowIfEmpty (I'm not picky on the name of the property).  This allows the user to have the grid insert an item into the IList if so necessary.

     Thanks,

    Jesse

    • Post Points: 60
  • 05-18-2007 12:24 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 723
    • Points 16,775

    Re: EntityGridView CustomProc from View adds a null record

    Jesse,

    Thanks for the patch, much appreciated. Just to clarify few points ... I'm trying to replicate the issue you had - where you don't see the EmptyDataText, but a blank record if there are no records, right?

    I've tried the custom sp against view that returns VList and the grid handles it the same way as TList, meaning if there are no records, then new object is inserted, to make column headers visible.

    I also agree there should be an option to control the display of the headers on and off.
    Mike Shatny
    -------------------------------------
    Member of the .netTiers team
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 60
  • 05-18-2007 4:55 PM In reply to

    • basolutions
    • Top 100 Contributor
    • Joined on 03-21-2007
    • Denver, CO
    • Posts 51
    • Points 1,175

    Re: EntityGridView CustomProc from View adds a null record

    You're welcome for the patch.  I will probably be submitting a few more for little things that cause me grief.  Now that I am more comfortable with the entire architecture, I don't feel so overwhelmed by modify the templates... ;) 

    Yes, you are correct, it displays a blank row in the grid.  I assumed it was just VList, but that is in large part because I almost never write custom procs for existing entities, but rather end up writing custom views and custom procs to meet the need of my requirements.

    Maybe a future option would be to extend the grid just a little futher to do just as you suggested for displaying the headers even when there is no data, and without having to insert a blank row.

    Thanks,

     Jesse

    • Post Points: 60
  • 06-11-2008 10:13 PM In reply to

    • Xcalibur
    • Not Ranked
    • Joined on 06-10-2008
    • Posts 2
    • Points 70

    Re: EntityGridView CustomProc from View adds a null record

    Was this issue ever resolved properly?  As in, is there a property that can be set on the EGV to cause it not insert a null row (even if that means there are no headers).

    • Post Points: 5
Page 1 of 1 (7 items)
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems