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

R

Raja

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.
 
P

PeterKellner

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/default.asp?url=/library/en-us/dnaspp/html/ASP2memroleman.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top