Update command in asp:datagrid not working

I am trying to update data in two tables in SQL Server 2005. When the user clicks on the Update command on my asp:datagrid, the update statement is not being run. What am I doing wrong?
<asp:DataGrid ID="dgDCDetails" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource6">
                                <Columns>
                                    <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update"></asp:EditCommandColumn>
                                    <asp:TemplateColumn HeaderText="Good?" HeaderStyle-Font-Bold="true" ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:CheckBox ID="chkSelection" runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="OfferID" DataField="OfferID" Visible="false" ReadOnly="true" />
                                    <asp:TemplateColumn HeaderText="OfferID" Visible="False">
                                        <ItemTemplate>
                                            <asp:Label ID="lblOfferID" Text='<%# DataBinder.Eval(Container.DataItem,"OfferID") %>'
                                                runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="DealCapID" DataField="DealCapID" ReadOnly="true" />
                                    <asp:TemplateColumn HeaderText="DealCapID" Visible="False">
                                        <ItemTemplate>
                                            <asp:Label ID="lblDealCapID" Text='<%# DataBinder.Eval(Container.DataItem,"DealCapID") %>'
                                                runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="ProspectID" DataField="ProspectID" ReadOnly="true" />
                                    <asp:TemplateColumn HeaderText="ProspectID" Visible="False">
                                        <ItemTemplate>
                                            <asp:Label ID="lblProspectID" Text='<%# DataBinder.Eval(Container.DataItem,"ProspectID") %>'
                                                runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="Prospect" DataField="Prospect" ReadOnly="true" />
                                    <asp:TemplateColumn HeaderText="Prospect" Visible="False">
                                        <ItemTemplate>
                                            <asp:Label ID="lblProspect" Text='<%# DataBinder.Eval(Container.DataItem,"Prospect") %>'
                                                runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="QuoteType" DataField="quotetype" ReadOnly="true" />
                                    <asp:TemplateColumn HeaderText="QuoteType" Visible="False">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="lblQuoteType" runat="server" Text='<%# Bind("quotetype") %>' Width="50"></asp:TextBox>
                                        </EditItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="Term" DataField="ContractTerm" ReadOnly="true" />
                                    <asp:TemplateColumn HeaderText="Term" Visible="False">
                                        <ItemTemplate>
                                            <asp:Label ID="lblContractTerm" Text='<%# DataBinder.Eval(Container.DataItem,"ContractTerm") %>'
                                                runat="server" />
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="Price" DataField="contractprice1" SortExpression="contractprice1" />
                                    <asp:TemplateColumn HeaderText="Price" Visible="False">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("contractprice1") %>'></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("contractprice1") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="EMS" DataField="contractprice2" SortExpression="contractprice2" />
                                    <asp:TemplateColumn HeaderText="EMS" Visible="False">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("contractprice2") %>'></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("contractprice2") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="EMSVersion" DataField="EMSVersion" ReadOnly="true" />
                                    <asp:BoundColumn HeaderText="StartDate" DataField="firstmthofprice" ReadOnly="true" />
                                    <asp:BoundColumn HeaderText="ContStartSwitch" DataField="contstart_switch" SortExpression="contstart_switch" />
                                    <asp:TemplateColumn HeaderText="ContStartSwitch" Visible="False">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("contstart_switch") %>'></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("contstart_switch") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="ContEndSwitch" DataField="contend_switch" SortExpression="contend_switch" />
                                    <asp:TemplateColumn HeaderText="ContEndSwitch" Visible="False">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("contend_switch") %>'></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("contend_switch") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="SwitchType" DataField="switchtype" SortExpression="switchtype" />
                                    <asp:TemplateColumn HeaderText="SwitchType" Visible="False">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("switchtype") %>'></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("switchtype") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="CommissionType" DataField="commtype" SortExpression="commtype" />
                                    <asp:TemplateColumn HeaderText="CommissionType" Visible="False">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("commtype") %>'></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label6" runat="server" Text='<%# Bind("commtype") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:BoundColumn HeaderText="CommissionDescription" DataField="Description" ReadOnly="true" />
                                </Columns>
                            </asp:DataGrid>
 
 
 
  
 
<asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:StikeData %>"
        SelectCommand=" SELECT enrollcustomer.OfferID, enrollcustomer.DealCapID, tbl_offer_1_price.ProspectID, tbl_offer_1_price.Prospect, enrollcustomer.quotetype, ContractTerm, cast(round(enrollcustomer.contractprice1, 6) as decimal(6,6)) as contractprice1, cast(Round(enrollcustomer.contractprice2, 6) as decimal(6,6)) as contractprice2, enrollcustomer.EMSVersion, enrollcustomer.firstmthofprice, CONVERT(varchar(10), contstart_switch, 101) as contstart_switch , CONVERT(varchar(10), contend_switch, 101) as contend_switch , enrollcustomer.switchtype, tbl_offer_1_price.commtype, pricing_market.dbo.tbl_Commission_Codes.Description FROM tbl_offer_1_price inner join EnrollCustomer  ON tbl_offer_1_price.dealcapid= EnrollCustomer.dealcapid left outer join pricing_market.dbo.tbl_Commission_Codes ON tbl_offer_1_price.commtype = pricing_market.dbo.tbl_Commission_Codes.[Commission Code] WHERE tbl_offer_1_price.analystid_brokerrep = @AnalystID and EnrollCustomer.DCApproved = 0; "
        UpdateCommand="UPDATE tbl_Offer_1_Price SET Price = @contractprice1, EMS_adder = @contractprice2 , ContStart_Switch = @contstart_switch , ContEnd_Switch = @contend_switch , SwitchType = @switchtype, CommType = @commtype WHERE OfferID = @OfferID; UPDATE EnrollCustomer SET ContractPrice1 = @contractprice1, ContractPrice2 = @contractprice2 , SwitchType = @switchtype WHERE OfferID = @OfferID; ">
        <SelectParameters>
            <asp:ControlParameter Name="AnalystID" ControlID="ddlAnalyst" DefaultValue="0" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="contractprice1" Type="Decimal" />
            <asp:Parameter Name="contractprice2" Type="Decimal" />
            <asp:Parameter Name="contstart_switch" Type="String" />
            <asp:Parameter Name="contend_switch" Type="String" />
            <asp:Parameter Name="switchtype" Type="String" />
            <asp:Parameter Name="commtype" Type="Int32" />
            <asp:ControlParameter Name="OfferID" ControlID="lblOfferID" Type="String" PropertyName="Text" />
        </UpdateParameters>
    </asp:SqlDataSource>

Open in new window

LVL 3
utlonghornjulieAsked:
Who is Participating?
 
Gyanendra SinghConnect With a Mentor ArchitectCommented:
its not DataKeyField its  datakeynames
0
 
Gyanendra SinghArchitectCommented:
set your datakeys value in grid ..

<asp:DataGrid ID="dgDCDetails" runat="server"  DataKeys="OfferID" AutoGenerateColumns="False" DataSourceID="SqlDataSource6">
0
 
utlonghornjulieAuthor Commented:
I added it, but it is still not working.

<asp:DataGrid ID="dgDCDetails" runat="server" DataKeyField="OfferID" AutoGenerateColumns="False"
                                DataSourceID="SqlDataSource6">
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.