473,465 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ObjectDataSource, GridView versus Business/Object Model

I am struggling with the following situation :

Suppose I have an Object model of a house. The house can contain 0 or
more chairs. Lets say the House class looks like this:

class House
{
private List<Chair_chairs;
public List<ChairChairs
{
get
{
return _chairs;
}
set
{
_chairs = value;
}
}
}

When I want to connect this to a GridView I can easily do ('house' is
of course an instance of class 'House'):

theGridView.DataSource = house.Chairs;
theGridView.DataBind();

Works perfect until you set 'AutoGenerateEditButton' to true, you get
an error saying something like 'The GridView fired event RowEditing
which wasn't handled'.

Ok, so I decided to add an ObjectDataSource to my aspx page. I added
the following method to class 'House' (needed for the 'SelectMethod'
property of the ObjectDataSource):

public List<ChairsGetChairs()
{
return Chairs;
}

The problem is here that the ObjectDataSource instance is creating a
complete new House instance before calling this method which I do not
want because my house instance already exists!

So finally I decided to create a new (static class) with the above
method defined as static.

class ChairsCollection
{
private static List<Chair_chairs;
public static List<ChairChairs
{
get
{
return _chairs;
}
set
{
_chairs = value;
}
}

public static List<ChairsGetChairs()
{
return Chairs;
}

}

I initialiaze the 'Chairs' property with the one in my house instance
and this works.

Now my question is, is all this work around code needed. Can this be
done simpeler?

Thanks for any help!

Yours sincerely,

Evert Wiesenekker

Aug 3 '06 #1
0 1179

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ole M | last post by:
I'm having some trouble using the ObjectDataSource in ASP.NET 2.0. I have a wrapper that contains the static methods for Select and Update. The Update-method takes the business object as...
0
by: family | last post by:
I have few classes in my business layer like: Country: CountryId (int) CountryName (string) CountryManager: GetAllCountry AddCountry RemoveCountry
2
by: Jami Bradley | last post by:
I'm in need of some design suggestions! We have a fairly large DB with thousands of users accessing data throughout the day. I have been given the task of restructuring a core part of the web...
5
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are...
4
by: GaryDean | last post by:
I have an objectdatasource reading a dataset and I have a gridview using that objectdatasource (at design time). It binds fine but I need to clear it. myGridView.DataSource = null:...
6
by: =?Utf-8?B?V2F5RG93blVuZGVy?= | last post by:
When I link an ObjectDataSource to a business object, it appears that the Refresh Schema button does nothing. I have added a property to the business object and want to display this new property...
1
by: Max2006 | last post by:
Hi, I am truing to find a pattern for my Business Logic Layer to be able to work fine win ObjectDataSource's Update method. The challenge is ObjectDataSource is not able to work with an...
5
by: cmrchs | last post by:
Hi, I'm trying out Databinding to a Data Acces Layer using a ObjectDataSource-control The Update works fine but the Delete-method doesn't. when debugging I see that my productID-parameter is...
0
by: steve | last post by:
I have been fighting with trying to update a GridView for a while. I don't want to use the "built-in" way to do it because I am using business layer methods for updating and deleteing and I don't...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.