New Posts New Posts RSS Feed: Help needed.. Binding an object property
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Help needed.. Binding an object property

 Post Reply Post Reply
Author
yokibitz View Drop Down
Newbie
Newbie


Joined: 27-Feb-2008
Posts: 3
Post Options Post Options   Quote yokibitz Quote  Post ReplyReply Direct Link To This Post Topic: Help needed.. Binding an object property
    Posted: 27-Feb-2008 at 3:01am
I have table called SubCategory.. Its fields are ID, Category ID, and SubCatDescription..
 
I need to display in a gridview the following fields:
 
ID, CategoryDescription, and SubCatDescription...
 
How do I do that.
 
I'm a newbie not only in DevForce but also in asp.net programming, please help me.. thanks!
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 27-Feb-2008 at 10:20am
I can't tell whether you are trying to build a Windows application or an ASP.NET application.
 
If you are trying to build a Windows application, see the Fundamentals Tutorial on "Populating a WinForm".
 
If you are trying to build an ASP.NET application, seen the Advanced Tutorial on "ASP.NET Apps using the ASPDataSource".
 


Edited by davidklitzke - 27-Feb-2008 at 10:22am
Back to Top
yokibitz View Drop Down
Newbie
Newbie


Joined: 27-Feb-2008
Posts: 3
Post Options Post Options   Quote yokibitz Quote  Post ReplyReply Direct Link To This Post Posted: 27-Feb-2008 at 2:34pm
Oh sorry.. I forgot to tell you guys that i'm building a asp.net application..
 
Thanks 4 giving some time looking into my problem.. I can populate a gridview using aspdatasource, my problem is how can I get a field that is not present my subcategory table but is present in a category table..
 
SubCategory Table:
 
SubcategoryID, Category ID, SubcategoryDescription
 
 
 
Category Table:
 
Category ID, CategoryDescription
 
 
 
I need to get and output CategoryDescription in my gridview. My entity adapter manager is typeof(Subcategory).
 
 
Thanks in advance!


Edited by yokibitz - 27-Feb-2008 at 2:56pm
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 27-Feb-2008 at 4:55pm
I guessed that you wanted to build an ASP.NET application.  That is why I suggested that you study the Advanced Tutorial on "ASP.NET Apps using the ASPDataSource".
 
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Posted: 28-Apr-2008 at 6:26am
"ASP.NET Apps using the ASPDataSource". is a great tutorial, but it stops short of making the grid editable.  How do you bind the ASPDataSource to a grid so that the grid rows can be in-place edited?  I have tried many different configurations but cannot seem to get the EntityAdapterManager.UpdateEntity method to fire under any circumstances.

Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 28-Apr-2008 at 9:36pm
I have figured out much of what needs to be done.  I'll do this with the tutorial
 
The first thing that you will need to do is create an UpdateEntity method for the OrderAdapterManager.
 
You will also need to enable Select, Edit, and Delete for the GridView.  Set AutoGenenerateEditButton, AutoGeneneratSelectButton,  and AutoGenenerateDeleteButton to True.  When you open the GridVIew, it will look something like the picture at the end of this post:
 
Continue on.  Eventually, you will select, Edit and Update.  Then you will need to debug your UpdateEntity code.  Eventually , I will build working example.
 
 
 


Edited by davidklitzke - 29-Apr-2008 at 9:32am
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Posted: 29-Apr-2008 at 6:05am
Thank you for looking in to this.  I appreciate the help because I am stumped.
I set up this code in a standard asp:gridview.  I've configured the binding and created that UpdateEntity method.  At least the gridview fires the GridView.HandleUpdate method which calls the AspDataSourceView.,ExecuteUpdate method.  However, the parameters to the UpdateEntity method are all null.  The "paramaters" paramter and the oldvalues parameter have a collection in them, but the elements of the collection are all null.  What am I missing? 
With the Telerik radgrid, I can't even get the UpdateEntity method to be called.  I will stick with the standard GridView until we get that working, then return to the radgrid.  Is there some other property or setting in the Grid/GridColumns that I need to be setting to make them update properly?
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Posted: 29-Apr-2008 at 6:08am
I noticed that the default binding of the grid was to make most of the columns in the grid readonly.  Is there a setting in the configuration of the AspDataSource or the ideablade class it is bound to that is making those columns readonly?  If I change the grid column to not be readonly, is the underlying data source still readonly anyway?
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 29-Apr-2008 at 9:06am
I got this to work for at least one column of the Order Table (Ship Address).  Here are the steps:
 
(1) You must add the Id column to the Order Grid.  Otherwise, the UpdateEntity code will have no way of knowing which Order it is supposed to update,
 
(2) You need no Update Parameters collection.
 
(3) Use this code for Update Entity:
 

public override int UpdateEntity(IOrderedDictionary parameters,

IDictionary keys, IDictionary values,

IDictionary oldvalues) {

long id = 0;

foreach (DictionaryEntry de in oldvalues) {

if ((String)de.Key == "Id") {

id = (long)System.Convert.ToInt64(de.Value);

}

}

PrimaryKey pk = new PrimaryKey(this.EntityType, id);

DoStandardUpdateSingleEntity(pk, values);

return (int)1;

}



Edited by davidklitzke - 29-Apr-2008 at 9:06am
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Posted: 29-Apr-2008 at 6:40pm
This code made the difference.  Now the update is working fine.  Next I have to get Add and Delete to work...  there's always something :)
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 29-Apr-2008 at 11:03pm
Insert looks like it will be a little tougher, a little search on the web for "insert" and "grid view" all give you advice like this:

Natively the GridView doesn't support the insertion of records.  However you can manipulate the footerrow in such a way that you can use it as an insertion row.  These are the steps :

1. Enable your gridview to show footers.
2. Make all editable columns and the command column into templatefields
3. Add the appropriate Textboxes and validationcontrols to the footer template of each column; name all the textboxes.
4. Add an Insert button to the column containing the buttons. Set it's command to Insert and make an eventhandler for the click event.
5. Add an onInserting eventhandler to your datasourcecontrol

I just post the source from my designer and the relevant eventhandlers to this article, the rest is up to you.

Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Posted: 30-Apr-2008 at 6:39am
that sounds like an ordeal.  I'm going to work with Telerik support to see if I can get them to help me figure some of this out.

What does the code look like in the OrderAdapterManager to support Insert and Delete?
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 30-Apr-2008 at 2:12pm

I haven't yet figured out what the Insert code will look like if we decide to use the approach suggested by last post.

I was wondering if you could try implementing the Delete.  I could easily do this myself, but I think it would be a good exercise for you if you tried to do it:
 
Here's how:
 
(1) Compute the primary key of the row you are trying to delete.  Use exactly the same logic as is used by UpdateEntity for the Orders Grid
 
(2) Use exactly the sane logic to delete the Order as is used in DeleteEntities for the Employee Details View
Back to Top
skingaby View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 23-Apr-2008
Location: United States
Posts: 146
Post Options Post Options   Quote skingaby Quote  Post ReplyReply Direct Link To This Post Posted: 30-Apr-2008 at 5:27pm
I can do that.  I am not too interested in trying to work around the shortcomings of the ASP GridView control with regard to add.  It actually makes more sense to me to throw a dialog on screen for an add anyway, so that should be able to bind using the employee logic too.  I will see what I can do for both. 
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 30-Apr-2008 at 8:42pm
I agree with your plan.   If you want a simple button called "Insert New Order", I could write a button click handler that inserted a minimal order.  The user could then update the minimal order by using the "Edit" and "Update" buttons, but you might actually  prefer adding your own screen dialog for "Create New Order".  Give me a holler if you run into problems or need any help.
Back to Top
cdsmith View Drop Down
Newbie
Newbie
Avatar

Joined: 10-Dec-2007
Location: United States
Posts: 4
Post Options Post Options   Quote cdsmith Quote  Post ReplyReply Direct Link To This Post Posted: 11-Aug-2008 at 6:35am
I've run into these same issues so I'll show how I implemented the Delete operation:
 

public override int DeleteEntities(IOrderedDictionary parameters, IDictionary keys, IDictionary oldvalues)

{

int id = 0;

foreach (DictionaryEntry de in oldvalues)

{

if ((String)de.Key == "BudgetTemplateID")

{

 id = (int)System.Convert.ToInt32(de.Value);

}

}

PrimaryKey pk = new PrimaryKey(this.EntityType, id);

Entity ent = this.PersistenceManager.GetEntity(pk);

ent.Delete();

return (int)1;

}

In my testing so far, I'm finding that I also have to make my Id column VISIBLE, BudgetTemplateID in this case.  If I set the Visible property on the Id column to false, the column doesn't show up in the "oldvalues" list.
 
 
Christopher Smith
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down