473,387 Members | 1,534 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.

ObjectDataSource & GridView: Can't update when PK is readonly

Hi Everybody
Just playing with ObjectDataSource and noticed the following.
I have a Gridview which binds to a ObjectDataSource. ObjectDataSource
gets data from a typed dataset created with VWD. In the table from
which the data is coming has a Primary Key field.

Gridview is set to edit mode. DataKeyNames = "PK_Field". Now if PK
field is not readonly, then data is updated successfully. But if I set
PK Field to readonly, then data is not updated. During the debugging I
see that e.InputParameters does not return any value for readonly PK
field. Probably no textbox created for readonly field, so no value.

How can I have the Gridview to update a record with readonly Primary
Key field?
Offcourse, there are many other ways to update, but I do not believe
that if I turn my PK field to readonly, then I have to change a lot of
code.
I must be missing something.

Jun 7 '06 #1
1 2414
On 7 Jun 2006 08:10:35 -0700, "Raja" <ra***********@gmail.com> wrote:
Hi Everybody
Just playing with ObjectDataSource and noticed the following.
I have a Gridview which binds to a ObjectDataSource. ObjectDataSource
gets data from a typed dataset created with VWD. In the table from
which the data is coming has a Primary Key field.

Gridview is set to edit mode. DataKeyNames = "PK_Field". Now if PK
field is not readonly, then data is updated successfully. But if I set
PK Field to readonly, then data is not updated. During the debugging I
see that e.InputParameters does not return any value for readonly PK
field. Probably no textbox created for readonly field, so no value.

How can I have the Gridview to update a record with readonly Primary
Key field?
Offcourse, there are many other ways to update, but I do not believe
that if I turn my PK field to readonly, then I have to change a lot of
code.
I must be missing something.


I think you are missing something. The ODS I published on MSDN for
use with membership
http://msdn.microsoft.com/library/de...memroleman.asp
has it's prmiary key as Username. You need to set the
DataObjectField's first attribute to true and I think you will be OK.
In my code I actually have UserName set to readonly in my primary
gridview so I know it works.

Good luck

/// <summary>
/// This calls the base class UserName property. It is here
so we can tag
/// this property as the primary key so that datakeynames
attribute gets set in the data control.
/// </summary>
///
[DataObjectField(true,false,false)]
public override string UserName
{
get { return base.UserName; }
}
Peter Kellner
http://peterkellner.net
Jun 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Danny W | last post by:
Hi all, I'm trying to update a record using ObjectDataSource but got the following error: The 'PhotoCount' property on the type specified by the DataObjectTypeName property in...
1
by: Dotnet Gruven | last post by:
I've posted this in the adonet group, however it was suggested I might have better luck here.... ============================================================= I'm trying to use a typed dataset and...
5
by: Ole M | last post by:
I'm having some trouble using the ObjectDataSource in ASP.NET 2.0. I have a wrapper that contains the static methods for Select and Update. The Update-method takes the business object as...
4
by: Anne Catterick | last post by:
Hi, I have an british ASP.Net 2.0 application which is doing what (should) be very simple. But I am having issues. On my page I have a GridView as follows (some tags excluded for easy...
3
by: mthomason | last post by:
I keep getting this error when trying to update records using an ObjectDataSource. I have seen others post similar errors...but I haven't found any solutions. ObjectDataSource...
0
by: Phil | last post by:
Environment: XP sp2 VS.Net 2005 (Asp.Net 2.0 - c#) Sql Server 2005 Scenario: -Table (Table1) with two columns: Table1Id <- Primary Key Column1
7
by: M C | last post by:
Hi, This is a problem that has been haunting me for days and I've come to a complete dead-end. I'm using a objectdatasource to select and update a gridview control. Populating with select works...
0
by: Phillip Ian | last post by:
Tried this over in CSharp.General and didn't get anything, so I thought I'd try again here. If there's an AJAX specific group I could ask this in, please let me know...I did look. I'm trying to...
1
by: Steve Kershaw | last post by:
Hi, I have a problem in which I'm using a GridView with an ObjectDataSource as a data source. The problem is that when I use the ObjectDataSource UPDATE routine I must have the key column...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.