Can you still databind to a single object in ASP .Net 2.0?

G

Guest

I have a page with a business object that is populated by parsing input from
the page (specifically a scanned drivers license). I was hoping that I could
display the results using a details view or bound to labels in a table.

In .Net 1.1, I would have just bound the individual text fields to the
object. This does not apear to be an option in .Net 2.0. The
ObjectDatasource seemed to be what I wanted (after all, I am binding to an
object), but it requires a collection. Is there any way to bind to a a
single object?

I also tried to go into the html source and set the text properties to the
object values using the <%= %> syntax and the Eval syntax. These also did
not work, although I can insert <%= %>this directly into the html and it
displays the values. I may be setting other values at the server for these,
so it would be more advantageous for me to use a server control if possible.

I seems silly that something so simple to do in .Net 1.1 would be such a
pain in .Net 2.0, so I must be missing something. Does anyone know how to do
it?
 
G

Guest

Hi John,

In ASP.NET2.0 you can use the generic collections to make this single object
a list of only one object in it that you can databind to any server control
using the objectdatasource, e.g.

List<clsScannedDriverLicense> DriverLicenses = new
List<clsScannedDriverLicense>();
//this creates a generic collection for you that you can return from
//your BLL to the ObjectDataSource
DriverLicenses.Add(TheOneObjectThatYouHaveofType_clsDriverLicense);


The your ObjectDataSource would look like that:

<asp:ObjectDataSource ID="odsDL" runat="server"
SelectMethod="OrdersByCustomer"
TypeName="YourBLL.UtiltiesClassName"
DataObjectTypeName="clsScannedDriverLicense">
</asp:ObjectDataSource>
 
G

Guest

Okay, but this seems a little bit silly. I will need to create a method that
returns this collection for the sole purpose of databinding the object.

In 1.1 you could databind to anything, even other controls of the page. It
wasn't uncommon to bind the visibility property of a panel to a radio button
or other control on the page. From what you are telling me, to do the same
thing in .Net 2.0 I would have to create a method that would wrap the page in
a generic collection and return it to create the same kind of binding.

This seems like a step backwards.
 
S

sloan

You might be more interested in

"Binding" "DataBindings", which is more MVC, more work, but allows the
single entity situaiton you describe.

http://www.west-wind.com/presentations/aspnetdatabinding/aspnetdatabinding.asp


...

I do the databindings alot in winforms apps ......... and is worth the price
you pay.
For the web, I'm up in the air about it.

2.0 adds the ability to handle "Null" values with databinding, which is a
HUGE step and upgrade from 1.1.

...

example of the nulls:
Binding titleIdBinding =_ txtTitleId.DataBindings.Add("Text",
Me.m_model, "TitleId");

'Improved in .NET 2.0 //
http://msdn2.microsoft.com/library/y0h25we8(en-us,vs.80).aspx
'titleIdBinding.NullValue = "Type a TitleID Here";
 

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,007
Latest member
obedient dusk

Latest Threads

Top