无法“启用编辑”在我的网格视图上
我正在尝试将 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>
I'm trying to connect my gridview to a LinqDataSource to select, update, insert and delete records. I am able to get into edit mode and cancel out of edit mode but when I click update nothing happens.
I've found a few things online that say to check the "Enable Editing" box in the gridview smart tag but when I go into the smart tag the only check boxes that appear are: Enable Paging, Enable Sorting and Enable selection. The others don't appear. Dose anyone see a problem with what I am doing below?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过不使用匿名类型?在代码中,您无法随时更新。数据库中的类型...
Did you try it without using anonymous types? In code, you can't update anon. types in the database...
看起来这是由于我在 LinqDataSoruce 上设置了 Select 值引起的。请参阅下面更新的 LDS:
Looks like this was caused by me having the Select value set on my LinqDataSoruce. See updated LDS below: