views:

124

answers:

1

I have the following code that seems like it should set my insertParameter but everytime an insert happens it uses the default parameter. Do i need to do anything special to make this work?

Codebehind:

protected void SetInsertParams(object sender, LinqDataSourceInsertEventArgs e)
    {
        if (lbl_Personnel.Visible)
        {
            lds_Personnel.InsertParameters["BudgetLineTypeCode"].DefaultValue = "S";
        }
        else if(lbl_Operating.Visible)
        {
            lds_Personnel.InsertParameters["BudgetLineTypeCode"].DefaultValue = "O";
        }
        else if (lbl_SubContractor.Visible)
        {
            lds_Personnel.InsertParameters["BudgetLineTypeCode"].DefaultValue = "C";
        }
    }

From my aspx page:

        <asp:LinqDataSource ID="lds_Personnel" runat="server" OnSelecting="SetParams"
            ContextTypeName="nrm.FRGPproposal.FrgpropDataContext"
            TableName="BudgetLines" OnInserted="lds_Personnel_OnInserted" OnInserting="SetInsertParams" 
            Where="ProposalID == @PropNumber &amp;&amp; BudgetLineTypeCode == @BudgetLineTypeCode" 
            EnableDelete="True" EnableInsert="True" EnableUpdate="True">
            <WhereParameters>
                <asp:SessionParameter Name="PropNumber" SessionField="PropNumber" Type="Int32" />
                <asp:Parameter DefaultValue="S" Name="BudgetLineTypeCode" Type="Char" />
            </WhereParameters>
            <InsertParameters>
                <asp:SessionParameter Name="ProposalID" SessionField="PropNumber" Type="Int32"/>    
                <asp:Parameter DefaultValue="S" Name="BudgetLineTypeCode" Type="Char" />          
            </InsertParameters>
        </asp:LinqDataSource>
A: 

Found a solution. See updated function below:

protected void SetInsertParams(object sender, LinqDataSourceInsertEventArgs e)
    {
        BudgetLine bl = (BudgetLine)e.NewObject;
        if (lbl_Personnel.Visible)
        {
            bl.BudgetLineTypeCode = 'S';
            //lds_Personnel.InsertParameters["BudgetLineTypeCode"].DefaultValue = "S";
        }
        else if(lbl_Operating.Visible)
        {
            bl.BudgetLineTypeCode = 'O';
            //lds_Personnel.InsertParameters["BudgetLineTypeCode"].DefaultValue = "O";
        }
        else if (lbl_SubContractor.Visible)
        {
            bl.BudgetLineTypeCode = 'C';
            //lds_Personnel.InsertParameters["BudgetLineTypeCode"].DefaultValue = "C";
        }
    }
Abe Miessler