Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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
  #1 (permalink)  
Old February 3rd, 2007, 10:24 PM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Binding Label Inside GridView to different soruce

I have a situation with GridView. Gridview contains fields, one of which is foreign key (integer) but I want to show the description from the parent table e.g.

Table1: Client (Code, Name, Address etc)
Table2: JobMaster (Job, ClientCode, Date etc)

Table1 and Table2 have their respective DA classes

The gridview on the form is binded to an objectdatsasource that retrieve data from table2 above. Second field i.e. ClientCode is a foreign key that belongs to Table1. Now instead of showing id I would like to show the Name of client from table1. How is that possible?

Help much appreciated
  #2 (permalink)  
Old February 4th, 2007, 07:49 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

There are a few ways to do this; one is the way you suggested earlier, where you query the database for each row you're adding. However, that's a bit inefficient, as you need to get into the database for each item.

As an alternative, you could create a strongly typed Client or ClientInfo object on the JobMaster. With a Client, the jobMaster.Client.Id would contain its ID, jobMaster.Client.Name would contain its name and so on.

With a ClientInfo object you can do pretty much the same, but skip the non relevant info like Address. That way, you have a light-weight object you can attach to JobMaster to provide details about the client.

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old February 4th, 2007, 07:57 AM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I have two entity classes for JobMaster and Client. JobMaster contains ClientID which is an integer holding the id. What you are suggesting is to have Client within JobMaster as of type Client rather than just an id. Is that correct?

I am using ObjectDataSource so does it support something like this and how can we bind i.e. <%# ??? %> in itemtemplate?

TNA

  #4 (permalink)  
Old February 4th, 2007, 08:04 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, that's what I am suggesting. Either make it a Client property or create a new light-weight ClientInfo object.

You can bind by casting it to an appropriate object type, and then access the ID or Name.

Search the P2P forum for the keyword NameValue. You'll find a number of posts about databinding with another complex object called NameValue. You'll see some examples about using the object in the markup and in the code behind.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #5 (permalink)  
Old February 4th, 2007, 06:25 PM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thank you for your instant replies. By the way, name of your book, instant results does match the way you quickly provide feedback. Its always good to see someone sharing knowledge. I think that sharing is the only way one can GAIN knowledge as well.

I have general architecture related queries and as your an architect, I thought it would be best to share my thoughts with you and get your suggestions.

With ASP.NET usually there are three layers i.e. User Interface (UI), Business Logic (BLL) and Data Access (DAL). ASP.NET introduced a very useful control ObjectDataSource that lets you bind custom objects. Now the thing I am a bit confused is that if UI needs to manipulate some data it can request DAL e.g. to retrieve a list of Clients one would bind ObjectDAtaSource with a method of DAL that gives back list of Client object. If one wants to delete something, a method of DAL is invoked by ObjectDataSource (ODS). This is all fine. Now another layer of Business Processes is required in situations where we want to orchestrate a process e.g. a process that will invoke three DAL's to delete/insert/update some objects (into tables). Now in this situation will/should the ODS be binded with the Business Process layer object/service?

I am an architect/team lead, though not as experienced as yourself, but I love to learn. I would be really thankful if you can share some ideas with me about how you architect your products. I understand that it depends on the project but of course there always is a pattern behind work of every individual. What is your pattern? e.g. What sort of layering system you use and more importantly if possible to share, how do you architect a solution?

I will also be greatful if you can point me to some links related to architectures (Books, articles etc). I have started your book and its very useful, well its something I look in a book i.e. rather than tons of theory and small code samples, less theory and teach by implementing real-world scenarios.

Many thanks once again. Much appreciated.

Tahir

  #6 (permalink)  
Old February 4th, 2007, 06:35 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Tahir ,

I just, as in minutes ago, finished part one of an article series about n-tier design: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=416

Although it's targeted at a small, simplified web application, many of the concepts are usable in larger applications as well.

The article series describes my thoughts and ideas about layering in web applications. Many of the concepts from the article are used in day-to-day web sites that I design. I am afraid you'll have to wait a while till part two that deals with code. I am working on it at the moment, but it isn't ready for publication yet. Hopefully, next week it is....

Regarding study material: there's tons of stuff I read, ranging from the MSDN magazine to Microsoft Architects magazine and www.google.com/*.* ;)
It's difficult to be precise without spending the next half hour listing sites.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #7 (permalink)  
Old February 4th, 2007, 06:48 PM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thanks for the link. I will be more precise my telling you how I usually design a solution and then you can point out the drawbacks and give me suggestions.

I work with SOA and have services for Data Access, Business Logic and Business Processes. Entities are then data objects (simple property get/set classes) which are passed between layers. Data Services will retrieve/insert/update/delete data from DB and build entity to pass back to UI or Business Services. From UI I directly access Data Services (passing entities) if no business logic is required. From UI I call a Business Process Service (passing entities) which in turn call Data Services and Business Services.

One thing I am keen of knowing is the difference of keeping entities seperate from the actual logic(either business or data access) OR having them together as an Object with fields and logic. Which one is better then other in your opinion?

Tahir

Tahir

  #8 (permalink)  
Old February 5th, 2007, 06:00 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

 
Quote:
quote:One thing I am keen of knowing is the difference of keeping entities seperate from the actual logic(either business or data access) OR having them together as an Object with fields and logic. Which one is better then other in your opinion?

As I answered in my article about n-tier design on a similar question from you: it depends.

I prefer to have smart objects where fields / data are mixed with methods / behavior. This makes them easier to use in many circumstances, including data binding in web forms. It also makes it easier to implement lazy loading, where properties aren't loaded from the database, unless they are accessed.

Your mileage may vary, though. What do you think of it? What do you prefer?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #9 (permalink)  
Old February 6th, 2007, 10:09 AM
Authorized User
 
Join Date: Jan 2007
Location: , , United Kingdom.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

I love OOA and OO concepts for designing architectures. The only concern that I have is that with smarter objects perfomance might be an issue when various layers (business/data) are deployed on different machines. In those circumstances passing an entity object (only fields) between layers improves perfomance. Well this is what I have heard/read. What do you think about performance and this topic: simple entity objects or smart objects?

I like the BugBase architecture, may be because that is how I am used to work. I am more inclined towards SAO with only Entities being passed between BLL and DALs (as in BugBase).

Should we start another topic for this discussion as this is interesting for me and might be good idea to have a new topic. If you think a new topic is good idea then let me know and I or You can create a new topic.

I have great interest in architecture and software processes and that was the focus of my MSc research as well. I will like to have discussions with you regarding this if you are happy with that.

Tahir
  #10 (permalink)  
Old February 6th, 2007, 04:58 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I wouldn't consider that SOA. IMO, SOA is about loosely coupled services (often web services) while the BugBase certainly isn't.

It's much more a design similar to the others, but with a separate business object, and separate classes responsible for working with those business objects.

Based on a discussion with Peter (Planoie on this forum), I am rewriting my architecture article a little, to include separate Business Objects in a BO layer that are passed around the Bll and Dal layers. Until then, I have take the article off-line.

I said earlier I like to mix them (data and behavior in the same class), as they are easier to manage and it's also easier to implement lazy loading schemes. However, in my current implementation, they also break the idea of completely separate layers.

I'll try to post an update here when I'm ready....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding ComboBox inside ListView problem gunnjamie Windows Presentation Foundation 1 July 17th, 2008 02:13 PM
Binding SQLDataSource To A Label Control sg225551 ASP.NET 2.0 Basics 1 January 16th, 2008 10:36 AM
TextBox inside GridView michurin ASP.NET 2.0 Basics 2 January 13th, 2007 12:51 PM
DropDownList inside a GridView aidoco ASP.NET 2.0 Basics 0 October 13th, 2006 04:24 AM





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