DetailsView - LLBLGenDataSourceControl - Inserting values which don't appear on form

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 19-Feb-2007 09:54:41   

I'm using the code below to set up a DetailsView and a LLBLGenDataSourceControl. There is one column SourceControlSystemID which needs to be inserted a specific value from the ASP.NET page, and which shouldn't be typed in on the DetailsView.

I've tried a few approaches and can't this to work as NULLs are inserted into the column value rather values such as 1 or 2. Approaches tried include

1) DetailsView - Removing the BoundField for this field. 2) LLBLGenDataSourceControl - Changing the InsertParameter in the vssDatabaseDetailView_ItemInserting event so the DefaultValue property has the value say 1. 3) LLBLGenDataSourceControl - In the vssDatabaseDetailView_ItemInserting event change the value by accessing the Values property from the DetailsViewInsertEventArgs instance passed in.

Any thoughts would be appreciated?

    <asp:DetailsView ID="vssDatabaseDetailView" runat="server" AutoGenerateRows="False" DataKeyNames="SourceControlDatabaseId" Height="50px" Width="125px" OnItemInserted="vssDatabaseDetailView_ItemInserted" DataSourceID="llbGenSourceControlDatabaseDataSource" OnItemDeleted="vssDatabaseDetailView_ItemDeleted" OnItemInserting="vssDatabaseDetailView_ItemInserting" OnItemUpdated="vssDatabaseDetailView_ItemUpdated" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" AutoGenerateInsertButton="True">
        <Fields>
            <asp:BoundField DataField="FileLocation" HeaderText="FileLocation" SortExpression="FileLocation" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
            <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
            <asp:BoundField DataField="SourceControlDatabaseId" HeaderText="SourceControlDatabaseId"
                ReadOnly="True" SortExpression="SourceControlDatabaseId" Visible="False" />
            <asp:BoundField DataField="SourceControlSystemId" HeaderText="SourceControlSystemId"
                SortExpression="SourceControlSystemId"  Visible="False" InsertVisible="False" />
        </Fields>
    </asp:DetailsView>
    <cc1:LLBLGenProDataSource ID="llbGenSourceControlDatabaseDataSource" runat="server"
        DataContainerType="EntityCollection" EntityCollectionTypeName="MyApp.CollectionClasses.SourceControlDatabaseCollection, MyApp">
        <InsertParameters>
            <asp:Parameter Name="SourceControlSystemID" Type="Int32" />
        </InsertParameters>
    </cc1:LLBLGenProDataSource>
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 19-Feb-2007 10:08:45   

Do you have any code in the code behind?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 19-Feb-2007 10:27:14   

Mainly this one in Page_Load

 if ( ! IsPostBack)
        {
            // The source control system the databases are related to 
            // is passed on the query string.
            SourceControlSystemID = Convert.ToInt32(Request.QueryString["SourceControlSystemID"]);

            // TODO Test putting in session and accessing this way
            Session["SourceControlSystemID"] = SourceControlSystemID;
            
            // Filter the databases displayed to only those for this source control system.
            IPredicate vssDatabasesFilterElement = (SourceControlDatabaseFields.SourceControlSystemId == SourceControlSystemID);
            PredicateExpression predicateExpression = new PredicateExpression(vssDatabasesFilterElement);
            llbGenSourceControlDatabaseDataSource.FilterToUse = predicateExpression;
            
            // If no databases have been created then ensure the 
            // detail view is in insert mode.
            if (vssDatabasesGridView.Rows.Count == 0)
            {
                vssDatabaseDetailView.ChangeMode(DetailsViewMode.Insert);
            }

            // TODO Is this required?
            llbGenSourceControlDatabaseDataSource.Refetch = true;
        }

and this one

 protected void vssDatabaseDetailView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["sourceControlSystemID"] = SourceControlSystemID;
    }
Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 19-Feb-2007 15:14:47   

Hi,

I saw you get SourceControlSystemID from the query string. Did you try using QueryStringParameter :

<asp:QueryStringParameter Name="SourceControlSystemID" QueryStringField="SourceControlSystemID" />

Posts: 254
Joined: 16-Nov-2006
# Posted on: 19-Feb-2007 15:42:39   

Yes I certainly did however this is only available the first time the page is requested i.e. when Page.IsPostBack is false.

On each subsequent post back the value is not present. I did however try using the parameter from a Session variable however this didn't work.

Any other thoughts or ways I can diagnose this issue further?

Posts: 254
Joined: 16-Nov-2006
# Posted on: 20-Feb-2007 12:37:11   

Did anyone have any thoughts on this?

I could only manage to get this working by changing the LivePersistanece property to false and then had to implement this event as follows

    protected void llbGenSourceControlDatabaseDataSource_PerformWork(object sender, PerformWorkEventArgs e)
    {
        List<UnitOfWorkElement> uowElement = e.Uow.GetEntityElementsToInsert();
        SourceControlDatabaseEntity database = uowElement[0].Entity as SourceControlDatabaseEntity;
    
        // Set the source control system for the newly created database.
        database.SourceControlSystem = new SourceControlSystemEntity(SourceControlSystemID);
        database.Save();

    }
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Feb-2007 07:46:53   

Did anyone have any thoughts on this?

If LivePersistance = true, would you please post the HTML code where you have the InsertParameter set for the LLBLGenProDataSource?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 21-Feb-2007 09:48:55   

You specified the insertparameter as a 'parameter' but what's the source of the value for that parameter? E.g. is that querystring, session, a control on the page, a hidden form variable perhaps?

If that parameter specification doesn't have a source, it won't have a value and thus NULL will be inserted as the field isn't set to a value.

Could you explain where the value for the particular field has to come from? (control, query string etc.)

Frans Bouma | Lead developer LLBLGen Pro