Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ObjectDataSource & GridView: Can't update when PK is readonly

Reply
Thread Tools

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

 
 
Raja
Guest
Posts: n/a
 
      06-07-2006
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.

 
Reply With Quote
 
 
 
 
PeterKellner
Guest
Posts: n/a
 
      06-07-2006
On 7 Jun 2006 08:10:35 -0700, "Raja" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Readonly bound field returns null in update method Ismail ASP .Net 3 10-22-2008 07:17 PM
ObjectDataSource method as another ObjectDataSource David Thielen ASP .Net Web Controls 3 03-23-2006 01:50 AM
ObjectDataSource and ReadOnly Object Property =?Utf-8?B?Sm9leSBDaMO2bXBmZg==?= ASP .Net 0 01-14-2006 08:07 PM
ObjectDataSource and ReadOnly Object Property =?iso-8859-1?q?Joey_Ch=F6mpff?= ASP .Net 0 01-13-2006 11:07 PM
ASP.NET Readonly panel function with readonly checkbox, readonly radiobutton Jonathan Hyatt ASP .Net Web Controls 1 06-08-2004 07:42 PM



Advertisments