E
Evert Wiesenekker
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<Chair> Chairs
{
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<Chairs> GetChairs()
{
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<Chair> Chairs
{
get
{
return _chairs;
}
set
{
_chairs = value;
}
}
public static List<Chairs> GetChairs()
{
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
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<Chair> Chairs
{
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<Chairs> GetChairs()
{
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<Chair> Chairs
{
get
{
return _chairs;
}
set
{
_chairs = value;
}
}
public static List<Chairs> GetChairs()
{
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