ASP.NET 2.0 DataBind Object To Form Element

C

cmay

Is there any way to databind the properties of a business object, like
an Employee, to fields in a form in asp.net 2.0?



cmay
 
E

Erik Funkenbusch

Is there any way to databind the properties of a business object, like
an Employee, to fields in a form in asp.net 2.0?

You want ObjectDataSource. This allows binding controls to a business
object.
 
C

cmay

Is there any way to build to form controls, or do you have to use a
Gridview when using the ObjectDataSource?

Chris
 
E

Erik Funkenbusch

Is there any way to build to form controls, or do you have to use a
Gridview when using the ObjectDataSource?

You can bind any data source to form controls. It works the exact same way
youw ould bind them to a SqlDataSource.
 
E

Erik Funkenbusch

How do you set the datasource of a textbox that isn't inside a
gridview?

You don't. You set the datasource of it's container, such as a FormView.
 
C

cmay

Ok that is what I was doing, just want to make sure I wasn't missing
something.

Maybe you can help me with another thing I am trying to figure out.
My get and save functions in my Manager class look like this:
..GetCustomer( CustomerId ) (returns customer object)
..SaveCustomer( Customer , ModifiedById)

So from what I read, having a "Save" that takes the business object as
a parameter is ok, but I think I am erroring out because it can't
figure out what do to about the "ModifiedById" part.

ModifiedById is just the ID of the person using the webapp. Any idea
how I can inject that into the Update process?
If this isn't clear just post and I will elaborate.
 
C

cmay

Well I think I found a way to get it working using an adapter class
adapting my business layer to the objectdatasource.

But I think this is probably more work than its worth.

I will just manually write the values from my business object to my
form elements. Will probably take about 1/2 the time.
 
E

Erik Funkenbusch

I will just manually write the values from my business object to my
form elements. Will probably take about 1/2 the time.

If this is a one-off, then probably so. If you plan to re-use it, however,
then a more object oriented approach is called for.
 
C

cmay

Can you elaborate on this a little?

What level of reuse are you talking about? I was basically building
form to edit the data from a business object. In that situation I
don't think there is really a case for reuse in other places. The
manual modification of the templates in the HTML and the extra code
needed to be added to do validation anyway will need to be done
whenever I am going to edit a business object through a form.
 
E

Erik Funkenbusch

Can you elaborate on this a little?

What level of reuse are you talking about? I was basically building
form to edit the data from a business object. In that situation I
don't think there is really a case for reuse in other places. The
manual modification of the templates in the HTML and the extra code
needed to be added to do validation anyway will need to be done
whenever I am going to edit a business object through a form.

Well, an example might be that you create a Customer object. This customer
object can be reused in different places in your web stie. I don't know
the details of what you're trying to build, but typically business objects
are things that have some value for reuse, otherwise they wouldn't really
be business objects.
 
C

cmay

Erik,

I am not talking aboiut reusing the business objects. I am doing that
for sure. I am talking about the binding of their data to a form for
modification by the user.

So by doing this manually, a person goes to edit customer info, I get
their customer object and fill some textboxes and other controls with
data. Then when they make changes and click save, I recreate the
customer object from their input and send it back to the data layer to
be saved.

What I was trying to avoid was writing all the code to get and set all
the properties of the business object to the fields in the form.

Chris
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top