我有以下代码似乎应该设置我的insertParameter但每次插入时它都使用默认参数。我是否需要做一些特别的事情来使这项工作?
代码隐藏:
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";
}
}
从我的aspx页面:
<asp:LinqDataSource ID="lds_Personnel" runat="server" OnSelecting="SetParams"
ContextTypeName="nrm.FRGPproposal.FrgpropDataContext"
TableName="BudgetLines" OnInserted="lds_Personnel_OnInserted" OnInserting="SetInsertParams"
Where="ProposalID == @PropNumber && 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>
答案 0 :(得分:0)
找到解决方案。请参阅下面的更新功能:
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";
}
}