The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Need help binding esDataSource to gridview

Last post 05-20-2008, 11:57 AM by Scott.Schecter. 7 replies.
Sort Posts: Previous Next
  •  05-20-2008, 10:33 AM 9363

    Need help binding esDataSource to gridview

    Hey everyone,

    I've been banging my head against my desk for the last 3 hours trying to get a basic databinding to a gridview.  No matter what I seem to do, the gridview always comes back empty. Can anyone offer a suggestion?

    aspx:

     

    Code:
    1    <es:esDataSource ID="EsDS_SectionTypes" runat="server" OnesCreateEntity="EsDS_SectionTypes_esCreateEntity" OnesSelect="EsDS_SectionTypes_esSelect1" />
    2        <div style="float: left;">
    3        <asp:GridView ID="GridView1" runat="server" DataSourceID="EsDS_SectionTypes" EmptyDataText="No rows to display">
    4        </asp:GridView>
    5        </div>
    

    cs:

     

    Code:
    1    protected void Page_Load(object sender, EventArgs e)
    2        {
    3            if (!Page.IsPostBack)
    4            {
    5                CmsContentSectionTypes entity = new CmsContentSectionTypes();
    6                entity.Query.es.CountAll = true;
    7                entity.Query.es.CountAllAlias = "Count";
    8                if (entity.Query.Load())
    9                {
    10                   //EsDS_SectionTypes.TotalRowCount = (int)entity.GetColumn("Count");
    11               }
    12       }
    13   }
    14   
    15   protected void EsDS_SectionTypes_esSelect1(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e)
    16       {
    17           CmsContentSectionTypesCollection collection = new CmsContentSectionTypesCollection();
    18           
    19           // Ensure that there's always a sort to avoid the 'The ranking function "ROW_NUMBER" must have an ORDER BY clause' error
    20           //if (e.SortItems == null)
    21           //{
    22           //    collection.Query.OrderBy(collection.Query.Name.Ascending);
    23           //}
    24   
    25           // Assign the esDataSourcSelectEvenArgs Collection property
    26           //collection.LoadAll();
    27   
    28           //Response.Write("Num rows in collection: " + collection.Count);
    29           e.Collection = collection;
    30       }
    31   
    32   protected void EsDS_SectionTypes_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e)
    33       {
    34           CmsContentSectionTypes entity = new CmsContentSectionTypes();
    35   
    36           if (e.PrimaryKeys == null)
    37               entity.AddNew();
    38           else
    39               entity.LoadByPrimaryKey((int)e.PrimaryKeys[0]);
    40   
    41           // Assign the Entity
    42           e.Entity = entity;
    43       }
    
    Thanks in advance!
     
  •  05-20-2008, 10:44 AM 9364 in reply to 9363

    Re: Need help binding esDataSource to gridview

    On the esDataSource control click on it in design mode, do you have AutoSort and AutoPaging to false? If so then you must load the collection, otherwise the esDataSource will load it. Also, the Trial version comes with sample esDataSource projects that run against SQL Server's northwind, have you tried those?  If not at least look at those samples, it will work for you.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  05-20-2008, 10:54 AM 9365 in reply to 9363

    Re: Need help binding esDataSource to gridview

    Hi

    I don't develop web apps (yet) so haven't used the esDatasource but your code doesn't seem to instantiate the appropriate Loader - is this done elsewhere in your app?

    Cheers

    Martin

  •  05-20-2008, 10:54 AM 9366 in reply to 9364

    Re: Need help binding esDataSource to gridview

    In almost every case where we have had this reported it has been because the GridView's AllowPaging and AllowSorting didn't match the esDataSource's AutoPaging and AutoSorting properties respectively.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  05-20-2008, 11:34 AM 9367 in reply to 9366

    Re: Need help binding esDataSource to gridview

    One other thing, since I don't see any column markup in the gridview it would appear you have not configured the esDataSource via the smart tag yet either.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  05-20-2008, 11:37 AM 9368 in reply to 9364

    Re: Need help binding esDataSource to gridview

    I've tried with both loading the collection and just passing a new instance of it.  It returns an empty gridview either way.  I've littered Response.Write's throughout the code to see what's being called.  I see where every collection I pass contains 5 rows, yet, the gridview is always empty.  If I'm digressing from the northwind example anywhere I'm missing it as the only thing I'm changing the Employees object type.
  •  05-20-2008, 11:44 AM 9369 in reply to 9366

    Re: Need help binding esDataSource to gridview

    Ooooohhhh!  I didn't know the paging and sorting tags had to be same for both the datasource and the gridview!  I guess I'm another one of those cases now :-P

    Thanks! 

  •  05-20-2008, 11:57 AM 9370 in reply to 9369

    Re: Need help binding esDataSource to gridview

    So setting those properties on the GridView and esDataSource solved your issue?

    Regards,

    Scott Schecter
    EntitySpaces | My Site
View as RSS news feed in XML