我正在尝试将gridview连接到LinqDataSource以选择,更新,插入和删除记录。我能够进入编辑模式并取消编辑模式,但是当我点击更新时没有任何反应。
我发现网上有一些内容可以检查gridview智能标记中的“启用编辑”框,但是当我进入智能标记时,出现的唯一复选框是:启用分页,启用排序和启用选择。其他人没有出现。任何人都看到我在下面做的事情有问题吗?
<asp:GridView ID="gv_Personnel"
runat="server"
OnRowDataBound="gv_Personnel_DataBind"
AutoGenerateColumns="False"
ShowFooter="True"
DataKeyNames="BudgetLineID"
AutoGenerateEditButton="True"
AutoGenerateDeleteButton="True"
DataSourceID="lds_Personnel"
>
<Columns>
<asp:BoundField HeaderText="Level of Staff" DataField="LineDescription" />
<asp:BoundField HeaderText="Hrs/Units requested" DataField="NumberOfUnits" />
<asp:BoundField HeaderText="Hrs/Units of Applicant Cost Share" DataField="" NullDisplayText="0" />
<asp:BoundField HeaderText="Hrs/Units of Partner Cost Share" DataField="" NullDisplayText="0" />
<asp:BoundField FooterStyle-Font-Bold="true"
FooterText="TOTAL PERSONNEL SERVICES:" HeaderText="Rate"
DataFormatString="{0:C}" DataField="UnitPrice" >
<FooterStyle Font-Bold="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="Amount Requested"
ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right"
FooterStyle-BorderWidth="2" FooterStyle-Font-Bold="true">
<FooterStyle BorderWidth="2px" Font-Bold="True" HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Applicant Cost Share"
ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right"
FooterStyle-BorderWidth="2" FooterStyle-Font-Bold="true">
<FooterStyle BorderWidth="2px" Font-Bold="True" HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Partner Cost Share"
ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right"
FooterStyle-BorderWidth="2" FooterStyle-Font-Bold="true">
<FooterStyle BorderWidth="2px" Font-Bold="True" HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Projet Cost"
ItemStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right"
FooterStyle-BorderWidth="2" FooterStyle-Font-Bold="true">
<FooterStyle BorderWidth="2px" Font-Bold="True" HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="lds_Personnel" runat="server"
ContextTypeName="nrm.FRGPproposal.FrgpropDataContext"
Select="new (BudgetLineID, UnitPrice, LineDescription, NumberOfUnits)"
TableName="BudgetLines"
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>
</asp:LinqDataSource>
答案 0 :(得分:1)
您是否在不使用匿名类型的情况下尝试了?在代码中,您无法更新anon。数据库中的类型......
答案 1 :(得分:0)
看起来这是因为我在LinqDataSoruce上设置了Select值。请参阅以下更新的LDS:
<asp:LinqDataSource ID="lds_Personnel" runat="server"
ContextTypeName="nrm.FRGPproposal.FrgpropDataContext"
TableName="BudgetLines"
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>
</asp:LinqDataSource>