473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Update Primary Keys Through Detailsview

I have a 2 column table that contains FK to other tables in my app. The 2 columns together form the PK for the table. I want to be able to update these values using a Detailsview, but can't get the update to work, the record does not update. I tried adding additional parameters to the Update Parameters of the SqlDataSource, then setting those params programatically, but still does not work.

Expand|Select|Wrap|Line Numbers
  1. <asp:DetailsView ID="property_detail" 
  2.             DataSourceID="Details" AutoGenerateRows="false"
  3.             AutoGenerateInsertButton="true" 
  4.             AutoGenerateEditButton="true" 
  5.             AutoGenerateDeleteButton="true" 
  6.             EmptyDataText="Please select a record." 
  7.             DataKeyNames="ServiceProfileCode, Organization" GridLines="Both" 
  8.             OnItemInserted="CustomerDetail_ItemInserted"
  9.             OnItemInserting="CustomerDetail_ItemInserting" 
  10.             OnItemUpdated="CustomerDetail_ItemUpdated"
  11.             OnItemUpdating="CustomerDetail_ItemUpdating" 
  12.             OnItemDeleted="CustomerDetail_ItemDeleted"
  13.             runat="server">
  14.             <HeaderStyle BackColor="Navy" ForeColor="White" />
  15.             <RowStyle BackColor="White" />
  16.             <AlternatingRowStyle BackColor="LightGray" />
  17.             <EditRowStyle BackColor="LightCyan" />
  18.             <Fields>
  19.               <asp:BoundField DataField="ServiceProfileCode" HeaderText="ServiceProfileCode" />
  20.               <asp:BoundField DataField="Organization" HeaderText="Organization" />
  21.             </Fields>
  22.           </asp:DetailsView>
  23.  
  24.  
  25. <asp:SqlDataSource ID="Details" 
  26.       ConnectionString=
  27.         "<%$ ConnectionStrings:MyConnectionString %>"
  28.       runat="server" 
  29.       SelectCommand="SELECT * FROM [OrganizationXServiceProfile] 
  30.         WHERE ([ServiceProfileCode] = @ServiceProfileCode and [Organization] = @Organization)"
  31.       DeleteCommand="DELETE FROM [OrganizationXServiceProfile] 
  32.         WHERE [ServiceProfileCode] = @ServiceProfileCode and [Organization] = @Organization"
  33.       InsertCommand="INSERT INTO [OrganizationXServiceProfile] ([ServiceProfileCode], [Organization]) 
  34.         VALUES (@ServiceProfileCode, @Organization)"
  35.       UpdateCommand="UPDATE [OrganizationXServiceProfile] SET [ServiceProfileCode] = @ServiceProfileCode, 
  36.         [Organization] = @Organization
  37.         WHERE [ServiceProfileCode] = @ServiceProfileCodeOld and [Organization] = @OrganizationOld">
  38.       <SelectParameters>
  39.         <asp:ControlParameter ControlID="property_gv" 
  40.           Name="ServiceProfileCode" PropertyName="SelectedDataKey.Values[0]" 
  41.           Type="String" DefaultValue="1" />
  42.         <asp:ControlParameter ControlID="property_gv" 
  43.           Name="Organization" PropertyName="SelectedDataKey.Values[1]"
  44.           Type="String" DefaultValue="1" />
  45.       </SelectParameters>
  46.       <DeleteParameters>
  47.         <asp:Parameter Name="ServiceProfileCode" Type="String" />
  48.         <asp:Parameter Name="Organization" Type="String" />
  49.       </DeleteParameters>
  50.       <UpdateParameters>
  51.         <asp:Parameter Name="Organization" Type="String" />
  52.         <asp:Parameter Name="ServiceProfileCode" Type="String" />
  53.         <asp:ControlParameter ControlID="property_gv" 
  54.           Name="ServiceProfileCodeOld" PropertyName="SelectedDataKey.Values[0]" 
  55.           Type="String" DefaultValue="1" />
  56.         <asp:ControlParameter ControlID="property_gv" 
  57.           Name="OrganizationOld" PropertyName="SelectedDataKey.Values[1]"
  58.           Type="String" DefaultValue="1" />
  59.       </UpdateParameters>
  60.       <InsertParameters>
  61.         <asp:Parameter Name="Organization" Type="String" />
  62.         <asp:Parameter Name="ServiceProfileCode" Type="String" />
  63.       </InsertParameters>
  64.     </asp:SqlDataSource>
  65.  
  66.         protected void CustomerDetail_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
  67.         {
  68.             Details.UpdateParameters[2].DefaultValue = e.Keys[0].ToString();
  69.             Details.UpdateParameters[3].DefaultValue = e.Keys[1].ToString();
  70.         }
  71.  
  72.  
Sep 9 '08 #1
0 1036

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
7
by: robert | last post by:
i need to update a column which is a member of the PK on this table. there are some thousands of rows to be updated, many more thousand already in the table. so, i get a constraint violation...
0
by: Oystein | last post by:
Hi! I've got a aspx page with a textbox, a detailsview and a gridview. In the textbox i enter a jobnumber. If the jobnumber exists in the table, the detailsview shows the columns in the table in...
3
by: G .Net | last post by:
Hi Everybody I was wondering if anybody could help me with something that has been bothering me for some time. Basically, it is a problem I encountered some time ago with DataSets. I found a...
1
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi, I am a newbie to ASP.NET 2.0. This is driving me nuts! I think I might have a fundamental misunderstanding of how this all works! I am using a DetailsView which is populated dynaically at...
0
by: kamlesh | last post by:
Hi Experts, I have a question on the ASP.NET 2.0 Details view control I dont like using the SQLDataSource to bind the data to the DetailsView control.. I dont like the idea of placing Queries...
0
by: =?Utf-8?B?UGhpbCBI?= | last post by:
I have a detailsview control on an ASP.NET 2.0 page which is bound to methods in a business object through an ObjectDataSource. All of the bound methods work correctly, but I have a slight problem...
4
by: Barno77 | last post by:
Everytime I edit a record, and hit update I get duplicating lines in my Details View. Here's my If statement: If (Len(e.OldValues("AutoNumber")) > 0) Then sql = "UPDATE SHIP_LOG SET...
2
by: bednarz.thomas | last post by:
I have the following business Object(s): public class ParentObject { public ParentObject(string somestring) { ...- } ....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.