GridView: how to pass readonly ID to Update method of a DataSoureObject?

Discussion in 'ASP .Net' started by Bogdan, Mar 4, 2008.

  1. Bogdan

    Bogdan Guest

    Hi,

    I have a DataSourceObject with update method as follows:
    Update(ID, field1, field2).

    ID represents a value of a primary key in a table. The field is set to
    Readonly in the GridView. I use stored procedure to update a row in the
    table. The procedure takes ID, field1, and field2 as parameters (ID is
    needed to identify the row).

    The GridView does not seem to pass the ID to my DataSourceObject's Update
    method. Instead it tries to locate a method with a different signature
    which is Update(field1, field2). This just does not make any sense: without
    ID I cannot update the corresponding row. And of course, I can't make the
    ID to be editable in the GridView.

    All this is a bit confusing because I defined an Update method with correct
    signature, associated the object data source with the grid view (and
    implicitly instructed the grid view to use the Update method, I thought) and
    still, the grid view does its own thing and looks for a method with a
    different signature.

    Could someone please give me some ideas on how to tackle this problem? I'm
    quite new to asp.net and I'm sure that there is a proper (although not
    obvious) way of handling it

    Thanks,
    Bogdan
     
    Bogdan, Mar 4, 2008
    #1
    1. Advertising

  2. Put ID into DataKeyNames and, if I am not mistaken, you will have @ID
    parameter available in the datasource UpdateParameters.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Bogdan" <> wrote in message
    news:%23njs%...
    > Hi,
    >
    > I have a DataSourceObject with update method as follows:
    > Update(ID, field1, field2).
    >
    > ID represents a value of a primary key in a table. The field is set to
    > Readonly in the GridView. I use stored procedure to update a row in the
    > table. The procedure takes ID, field1, and field2 as parameters (ID is
    > needed to identify the row).
    >
    > The GridView does not seem to pass the ID to my DataSourceObject's Update
    > method. Instead it tries to locate a method with a different signature
    > which is Update(field1, field2). This just does not make any sense:
    > without ID I cannot update the corresponding row. And of course, I can't
    > make the ID to be editable in the GridView.
    >
    > All this is a bit confusing because I defined an Update method with
    > correct signature, associated the object data source with the grid view
    > (and implicitly instructed the grid view to use the Update method, I
    > thought) and still, the grid view does its own thing and looks for a
    > method with a different signature.
    >
    > Could someone please give me some ideas on how to tackle this problem?
    > I'm quite new to asp.net and I'm sure that there is a proper (although not
    > obvious) way of handling it
    >
    > Thanks,
    > Bogdan
    >
    >
     
    Eliyahu Goldin, Mar 5, 2008
    #2
    1. Advertising

  3. Bogdan

    Bogdan Guest

    Thanks, that works. I noticed that GridView _appends_ the ID automatically
    to the end of parameter list passed to the UpdateMethod, regardless of the
    method's signature and the presence of ID in <UpdateParameters> collection.
    What I needed to do for this thing to work was to define my data source
    update method as:
    Update(field1, field2, ID) . And of course, per your suggestion, I had to
    put ID into DataKeyNames (actually the framework did that automatically
    because ID is a primary key). I wish that the docs were more helpful in
    describing the process more clearly. The only thing that I could find was a
    statement simply saying that values in DataKeyNames are passed to the data
    source control. I could not find anything about the order, etc. If you
    happen to know any useful link that explains the process then I'd really
    appreciate it.

    Thanks again for your help,
    Bogdan


    "Eliyahu Goldin" <> wrote in
    message news:epW$...
    > Put ID into DataKeyNames and, if I am not mistaken, you will have @ID
    > parameter available in the datasource UpdateParameters.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Bogdan" <> wrote in message
    > news:%23njs%...
    >> Hi,
    >>
    >> I have a DataSourceObject with update method as follows:
    >> Update(ID, field1, field2).
    >>
    >> ID represents a value of a primary key in a table. The field is set to
    >> Readonly in the GridView. I use stored procedure to update a row in the
    >> table. The procedure takes ID, field1, and field2 as parameters (ID is
    >> needed to identify the row).
    >>
    >> The GridView does not seem to pass the ID to my DataSourceObject's Update
    >> method. Instead it tries to locate a method with a different signature
    >> which is Update(field1, field2). This just does not make any sense:
    >> without ID I cannot update the corresponding row. And of course, I can't
    >> make the ID to be editable in the GridView.
    >>
    >> All this is a bit confusing because I defined an Update method with
    >> correct signature, associated the object data source with the grid view
    >> (and implicitly instructed the grid view to use the Update method, I
    >> thought) and still, the grid view does its own thing and looks for a
    >> method with a different signature.
    >>
    >> Could someone please give me some ideas on how to tackle this problem?
    >> I'm quite new to asp.net and I'm sure that there is a proper (although
    >> not obvious) way of handling it
    >>
    >> Thanks,
    >> Bogdan
    >>
    >>

    >
    >
     
    Bogdan, Mar 5, 2008
    #3
    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. Raja
    Replies:
    1
    Views:
    3,363
    PeterKellner
    Jun 7, 2006
  2. swep
    Replies:
    0
    Views:
    401
  3. Ismail
    Replies:
    3
    Views:
    5,645
    Marc BICHARA
    Oct 22, 2008
  4. Jeff

    {newbie} GridView is readonly

    Jeff, Apr 13, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    346
  5. Jonathan Hyatt
    Replies:
    1
    Views:
    2,092
    Jonathan Hyatt
    Jun 8, 2004
Loading...

Share This Page