Solved

Update command in asp:datagrid not working

Posted on 2008-10-03
3
464 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 500 total points
ID: 22643476
its not DataKeyField its  datakeynames
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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