Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update command in asp:datagrid not working

Posted on 2008-10-03
3
Medium Priority
?
479 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22635900
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
ID: 22636466
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 2000 total points
ID: 22643476
its not DataKeyField its  datakeynames
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 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