Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> GridView, LLBLGenProDataSource2, and no ViewState
 

Pages: 1
LLBLGen Pro Runtime Framework
GridView, LLBLGenProDataSource2, and no ViewState
Page:1/1 

  Print all messages in this thread  
Poster Message
MattWoberts
User



Location:
Lancaster, UK
Joined on:
08-Apr-2004 10:24:31
Posted:
497 posts
# Posted on: 20-Sep-2007 15:23:16.  
Hi,

I am using a GridView bound to an LLBLGenProDataSource, with LivePersistance set to false.
Everything works fine until I disable ViewState on the GridView (which I need to do to reduce a BIG file size). The error I get is :

Code:
'SD.LLBLGen.Pro.ORMSupportClasses.ORMGeneralOperationException' occurred in System.Web.dll but was not handled in user code

Additional information: There are no primary key fields specified in the bound control and/or the bound control didn't specify any primary key fields. Update can't continue


I set the DataKeyNames on the grid (DataKeyNames="Id"), so obviously when the grid is posted back this information is lost because EnableViewState is false. So, just before the "UpdateRows" method of the grid fires, I tried setting this in code like this;-

GridView1.DataKeyNames = new string[] {"Id"};

But that doesn't make a difference either. Maybe it will only work IF ViewState is enabled for the grid...
Can anyone help?

Matt.

Matt  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14618 posts
# Posted on: 20-Sep-2007 16:00:25.  
I couldn't reproduce it using LLBLGen Pro v.2.5
I disabled the viewstate on the gridView, and everything worked as expected, eiditing rows using the EDIT & UPDATE grid commands worked without a flow.
I've tried with both LivePersistence set to true and false.

Could you please post a repro project working on northwind?
Thanks.



  Top
MattWoberts
User



Location:
Lancaster, UK
Joined on:
08-Apr-2004 10:24:31
Posted:
497 posts
# Posted on: 20-Sep-2007 16:12:33.  
I don't have the northwind database, but if you modify this to use any table with an "ID" primary key and a name column or something similar, you should get the same results:

Here's the grid and LLBLGen data source

Code:
        

            <llblgenpro:LLBLGenProDataSource2 ID="fuelTypes" runat="server" AdapterTypeName="Entropy.Envoy.DAL.Generated.DatabaseSpecific.DataAccessAdapter, Entropy.Envoy.DAL.GeneratedDBSpecific"
                DataContainerType="EntityCollection" EntityFactoryTypeName="Entropy.Envoy.DAL.Generated.FactoryClasses.FuelTypeEntityFactory, Entropy.Envoy.DAL.Generated"
                LivePersistence="false" OnPerformGetDbCount="GetDbCount" OnPerformWork="PerformWork" OnPerformSelect="PerformDBSelect">
            </llblgenpro:LLBLGenProDataSource2>


<asp:GridView EnableViewState="false" ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
            DataSourceID="fuelTypes">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            </Columns>
        </asp:GridView>


And heres the code behind

Code:
using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entropy.Envoy.DAL.Generated;
using Entropy.Envoy.DAL.Generated.DatabaseSpecific;
using Entropy.Envoy.DAL.Generated.EntityClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace AJAXEnabledWebApplication1
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            fuelTypes.AdapterToUse = GetDAA();
        }

        private static DataAccessAdapter GetDAA()
        {
            return
                new DataAccessAdapter(
                    "Stick a Valid Connection String here",
                    false,
                    CatalogNameUsage.ForceName,
                    "");
        }

        protected void PerformWork(object sender, PerformWorkEventArgs2 e)
        {
            List<UnitOfWorkElement2> insertItems = e.Uow.GetEntityElementsToInsert();

            foreach (UnitOfWorkElement2 item in insertItems)
            {
                // I do a bit of entity tweaking here, commented out for brevity
            }
            e.Uow.Commit(GetDAA(), true);
        }


        protected void PerformDBSelect(object sender, PerformSelectEventArgs2 e)
        {
            GetDAA().FetchEntityCollection(e.ContainedCollection, e.Filter, 0, e.Sorter, e.PrefetchPath);
        }

        protected void GetDbCount(object sender, PerformGetDbCountEventArgs2 e)
        {
            e.DbCount = GetDAA().GetDbCount(e.ContainedCollection, e.Filter);
        }

    }
}


This code won't work unless I enable ViewState on the Grid. I'm using LLBLGen 2.0 (2.0.7.122).

Thanks
Matt  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14618 posts
# Posted on: 20-Sep-2007 16:33:47.  
Quote:
This code won't work unless I enable ViewState on the Grid. I'm using LLBLGen 2.0 (2.0.7.122).

I don't have that old version, would you please try it out with the latest available build of v.2.0. Many things could have been solved since that bold version.

Also I would recommend if you try it out with v.2.5 using the "ASP.NET 2.0 databinding example", which is available in the Examples section of the v.2.5 downloads.


  Top
MattWoberts
User



Location:
Lancaster, UK
Joined on:
08-Apr-2004 10:24:31
Posted:
497 posts
# Posted on: 20-Sep-2007 17:27:16.  
Aha - I figured it out :-

Only setting the AdaptorToUse prop if the page hasn't done a postback solves the problem nicely :-

Code:
            if (!Page.IsPostBack)
                fuelTypes.AdapterToUse = GetDAA();


I appreciate your help though walaa, thanks Regular Smiley

Matt  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.