无法“启用编辑”在我的网格视图上

发布于 2024-08-25 01:05:05 字数 3893 浏览 5 评论 0原文

我正在尝试将 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 &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>
    </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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守不住的情 2024-09-01 01:05:05

您是否尝试过不使用匿名类型?在代码中,您无法随时更新。数据库中的类型...

Did you try it without using anonymous types? In code, you can't update anon. types in the database...

呆橘 2024-09-01 01:05:05

看起来这是由于我在 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>

Looks like this was caused by me having the Select value set on my LinqDataSoruce. See updated LDS below:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文