A bit confused...

A bit confused...

Old forum URL: forums.lhotka.net/forums/t/152.aspx


Aliator posted on Friday, May 19, 2006

Hi,

The fact is that books examples are quite complete and I don't find a single example for my need...

I have some small tables I want to edit directly from a GridView... Let's say a Family table

I now I need an editable list to bind to GridView, but how to create it ?

EditableRootList and EditableChild ? Do I need to create more BOs for this functionality ?

Thank you.

dean replied on Friday, May 19, 2006

Assuming csla 2.0 and each family object is a root object and you want to edit this in a grid view. Then create a collection class called Familys :

public class Familys
 inherits BusinessListBase( of Familys, Family)

This you should bind to the grid view and you should be able to edit the family objects.

Dean

phowatt replied on Friday, May 19, 2006

If I understand what you are asking you just want to edit a table using a GridView and are wondering what object types to use.  In my experience the most common example of editing a collection with a grid is an example like an order.  The root object is the order and the child collection are the order line items.  Your root object uses a stored procedure, let's call it GetOrder to retrieve the order and line items from the data base and returns two result sets.  The first result set is the order the second result set are the line items.  In the Data Access region in the DataPortal_Fetch method of the Order class the first result set is retrieved via a datareader and populates the order properties with the information from the order row.  Then the next result set is processed via the EditableChild collection class and the the Editable Child to poplulate the line item collection.

In your example I would do exactly the same thing except the the stored procedure would return only one result set which would be used to populate the Family collection.  The root object, let's call it mFamily would not retrieve any data from the database and it would have only one property lets say it is named FamilyRecords.  In my form I would then instantiate the EditableRoot class mFamily and bind my GridView to mFamily.FamilyRecords.  The only purpose of the root object in this case is to host the collection. I hope this helps

Aliator replied on Saturday, May 20, 2006

OK, understood...

Now I'm facing another problem, more related to ASP.Net itself...

In the page where I have the GridView, I have this error on FamilyDataSource_DeleteObject method:

"Object reference not set to an instance of an object." for this line of code:

string _FamilyId = e.Keys["FamilyId"].ToString();

I'm looking into Project Tracker sources, and see nothing special about handling Keys ?

What am I missing ?

RockfordLhotka replied on Saturday, May 20, 2006

If I understand correctly, you have a small table and you just want to allow the user to edit the data in that table - pretty much directly. No parent-child, nothing complex?

This is the Admin\Role and Admin\Roles classes in the ProjectTracker sample, and the associated RoleEdit.aspx page. Roles is an editable root collection, containing editable child objects.

Aliator replied on Sunday, May 21, 2006

Thank you, I 'll give it a try...

Copyright (c) Marimer LLC