Solved

Update command in asp:datagrid not working

Posted on 2008-10-03
3
445 Views
Last Modified: 2008-10-06
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

0
Comment
Question by:utlonghornjulie
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
Comment Utility
set your datakeys value in grid ..

<asp:DataGrid ID="dgDCDetails" runat="server"  DataKeys="OfferID" AutoGenerateColumns="False" DataSourceID="SqlDataSource6">
0
 
LVL 3

Author Comment

by:utlonghornjulie
Comment Utility
I added it, but it is still not working.

<asp:DataGrid ID="dgDCDetails" runat="server" DataKeyField="OfferID" AutoGenerateColumns="False"
                                DataSourceID="SqlDataSource6">
0
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 total points
Comment Utility
its not DataKeyField its  datakeynames
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now