views:

248

answers:

2

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 &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>
+1  A: 

Hey,

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

Brian
What would be an anonymous type in the above code?
Abe Miessler
Select="new (BudgetLineID, UnitPrice, LineDescription, NumberOfUnits)"
citronas
Yes Select New creates the anonymous type; work with the base table if possible.
Brian
A: 

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 &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>
Abe Miessler