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

Discussion in 'ASP .Net' started by Raja, Jun 7, 2006.

  1. Raja

    Raja Guest

    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.
    Raja, Jun 7, 2006
    #1
    1. Advertising

  2. Raja

    PeterKellner Guest

    On 7 Jun 2006 08:10:35 -0700, "Raja" <> 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/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
    PeterKellner, Jun 7, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny W

    GridView update with ObjectDataSource

    Danny W, Sep 8, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,067
    Danny W
    Sep 8, 2005
  2. =?iso-8859-1?q?Joey_Ch=F6mpff?=

    ObjectDataSource and ReadOnly Object Property

    =?iso-8859-1?q?Joey_Ch=F6mpff?=, Jan 13, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    509
    =?iso-8859-1?q?Joey_Ch=F6mpff?=
    Jan 13, 2006
  3. =?Utf-8?B?Sm9leSBDaMO2bXBmZg==?=

    ObjectDataSource and ReadOnly Object Property

    =?Utf-8?B?Sm9leSBDaMO2bXBmZg==?=, Jan 14, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    566
    =?Utf-8?B?Sm9leSBDaMO2bXBmZg==?=
    Jan 14, 2006
  4. Bogdan
    Replies:
    2
    Views:
    5,515
    Bogdan
    Mar 5, 2008
  5. Jonathan Hyatt
    Replies:
    1
    Views:
    1,901
    Jonathan Hyatt
    Jun 8, 2004
Loading...

Share This Page