Solved

Update command in asp:datagrid not working

Posted on 2008-10-03
3
450 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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Login 17 40
Reset asp.net login password 4 31
Executing SSIS with a Stored Procedure Permissions 12 22
How can my static class become undefined?? 8 13
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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

11 Experts available now in Live!

Get 1:1 Help Now