Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bogdan - 04 Mar 2008 22:02 GMT
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 - 05 Mar 2008 09:32 GMT
Put ID into DataKeyNames and, if I am not mistaken, you will have @ID
parameter available in the datasource UpdateParameters.

Signature

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

> Hi,
>
[quoted text clipped - 24 lines]
> Thanks,
> Bogdan
Bogdan - 05 Mar 2008 14:46 GMT
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

> Put ID into DataKeyNames and, if I am not mistaken, you will have @ID
> parameter available in the datasource UpdateParameters.
[quoted text clipped - 27 lines]
>> Thanks,
>> Bogdan

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.