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

B

Bogdan

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
 
B

Bogdan

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 said:
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 said:
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
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top