Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 24th, 2004, 02:39 PM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Editing SINGLE record in ASP.NET

Designed a form for loading a single record from a db via business object ( let's call it bo). The business object is initialized during Page_Load and returns a DataView object (named Person) which is used to bound to form controls. Init code as follows:
Code:
CBusObj bo = new CBusObj(System.Convert.ToInt32(Session["CurrentID"]));
this.DataBind();
Controls are bound to the DataView using DataBinder.Eval syntax and show selected data properly. No need of any grid, list, repeater and so on. Binding code as follows:
Code:
text='<%# DataBinder.Eval(bo.Person, "[0].Email1")%>'
After hitting a "save" button
  • no changes to the controls are available (e.g. textboxes)
  • selectedvalue properties of dropdowns aren't properly stored
  • no changes can be submitted to the db
The only statement in the "save button Click event is
Code:
bo.Person[0].Row.AcceptChanges();
Can't find a way out of it - any help would be highly appreciated. Thanks in advance and Merry Christmas to all!

Andreas
Reply With Quote
  #2 (permalink)  
Old December 28th, 2004, 07:19 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK - problem solved by incorporating the form in a datalist.
It works but, however it looks ugly to me using a list when only a single record is in scope.

So any better ideas are really welcome.

Andreas
Reply With Quote
  #3 (permalink)  
Old December 28th, 2004, 11:01 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The way I usually handle these kinds of forms is to load all the data programmatically driven by the page_load event. Then get the data from the controls in the onclick handler for the appropriate button(s) to update the database. IMO, two-way databinding in ASP.NET is (if it's even possible) more trouble than it's worth.
Reply With Quote
  #4 (permalink)  
Old December 28th, 2004, 09:09 PM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for answering.
As far as I understand your proposal I would have to collect all the data twice: once for validating and then for updating the database. Sounds not that effective. The ASP application I'm currently working on will be the Web interface for a very complex database application I wrote for a service agency. That application has to handle multilateral multipart contracts. The parts are depending on each other on several status levels. Each contract can be handled from several points of view: customer's view, agency's view and there are sub-contracters, freelancers and so on. For these reasons I decided to develop several business objects to handle the dependencies and wanted to bind the form controls directly to my BO's data objects. That way should let me use the business rules I've already developed for the local application and should be essential for driving the user through the web pages.
If I'm right your proposal does not bind the data properties of the form controls to the data objects but handles the values. That leads me to much more coding work.
I'm wondering why it seems to be impossible to bind form controls directly to user-defined data objects although there's an appropriate syntax available.

Sorry for any English mistakes and best wishes for a great 2005.

Andreas
Reply With Quote
  #5 (permalink)  
Old December 29th, 2004, 03:30 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The problem is with the stateless nature of a web page. Unlike a windows form application, your web form exists for only a brief amount of time (while the page is executing on the server). It is then sent to the browser and destroyed at the server. So you will always have to do some amount of reconstructing of objects/data at the server when the page is posted. This can be achieved thru storage of an object in view-state or session. This however could be taxing on the server resources if you are dealing with many or big objects. As experienced by many in the past, it's also sometimes not quite so reliable. It sounds like you might need to learn a bit more about web applications in general before you can successfully implement your business solution with a web app.
Reply With Quote
  #6 (permalink)  
Old December 30th, 2004, 05:42 AM
Registered User
 
Join Date: Dec 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nope,

developed some portals and pro web sites since 1996. The "stateless nature" was one of the reasons for my business objects (no viewstate necessary, session variables are much easier to handle) - this way I'm able to load data step by step and do not have to load it in regard to GUI states or actions.

The problem for me was not the page reload. From my point of views data-bound objects should be noticed about data changes via data-binding properties and can handle these changes through standard or user-defined events. Otherwise it makes no sense to me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp and asp dot net in single application rejoin2me ASP.NET 2.0 Basics 5 February 21st, 2007 12:26 PM
Online editing in asp.net bneeraj General .NET 0 February 3rd, 2005 09:32 AM
Editing in Datagrid with ASP.NET rotsey General .NET 0 October 22nd, 2004 01:38 AM
ASP.Net Single Single-on with Oracle Application S guhanath Oracle 0 October 6th, 2004 05:05 AM
Text Editing/Modification in VB.Net/ASP.Net joevnvdvc VS.NET 2002/2003 0 July 29th, 2003 12:56 PM



All times are GMT -4. The time now is 10:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.