simple question regarding DataPortal.Create

simple question regarding DataPortal.Create

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


dstarkey posted on Friday, October 20, 2006

In the project tracker app I see where some bo's props are set in the RunLocal DataPortas create method.  Specifically it sets the guid id.  I want to set some default values, and when stepping through the code I see these private variables are set correctly.  What I want to do, is display this new object with its default values, where the user can override the defaults by simply entering different data.  For example, say country = "USA"; 

My problem is even though the Create code runs, I cannot figure out how to display the input fields with the default values.  Instead I get empty text boxes.   How would you display the guid in project tracker when the user click on Add Project.  Thats all I need to know how to do.  Help is greatly appreciated.

Don

code snippets:

private void DataPortal_Create(Criteria criteria)

{

Ss_Type = "S";

military = "N";

indep_Contr = "N";

benefit_Opt = 11;

ValidationRules.CheckRules();

}

// want to add the code that will create NewEmp(); and bind this new emp object to DetailViews1.

protected void AddRoleButton_Click(object sender, EventArgs e)
{
this.DetailsView1.DefaultMode = DetailsViewMode.Insert;
MultiView1.ActiveViewIndex = (
int)Views.InsertView;
}

Dont know what I need, databind detailsView1??  Map from the new object but to what??? any help is greatly appreciated.

thanks

Don

Michael Hildner replied on Saturday, October 21, 2006

Hi Don,

If I understand you correctly, you can just create a datasource from your object and drag that datasource, or individual properties onto your form. Is that what you're looking for?

Mike

dstarkey replied on Saturday, October 21, 2006

I am looking for what it would take to modify the project tracker application so that the guid id assigned in the create method of the (bo project's with - Run Local attribute ) data portal would be be initially displayed as a default value of a new project, where a user could either accept or override this default id value.  As it is right now the  guid id is generated in the background and only becomes visible once the project has been inserted (ie in its editable state).  Please let me know if this is still unclear, or if this is in fact possible.

Thanks
Don

Brian Criswell replied on Saturday, October 21, 2006

Just add a button to the user interface.  When the button is pushed, it calls the ChangeId method (which you would add) on the project.  This method would set the id to a new Guid and call PropertyHasChanged("Id") (or whatever the corresponding property name is).

dstarkey replied on Saturday, October 21, 2006

So the only way to display default values for a new record is by having the page refresh in some manner??  By on_click or similar manner to refresh the page.  I am surprised that there is not a way to display default values of a new object when that object is created.  I still think we are missing something here???

Brian Criswell replied on Saturday, October 21, 2006

Sorry, I thought that is what you wanted because you want the user to be able to see it and then choose if they want to change it.  However, reading this thread again, are you having trouble seeing the value when you first create the item?  That sounds like the data binding was not set up properly.  Someone else would have to help you as I do not have ASP.NET experience.

dstarkey replied on Saturday, October 21, 2006

Yes thats the problem.  I see the default values created when instantiating a new object, but they are not displayed on the details view (insert mode).  Instead I have empty text boxes, even for those properties where default values were created.  Thanks for trying to help me with this!  All help is greatly appreciated.

Don

ajj3085 replied on Monday, October 23, 2006

Don,

Search on the forum, this has been discussed.  I think you need to use the binding source component that comes with Csla to get this working.

dstarkey replied on Monday, October 23, 2006

What is the binding source component??   And how does it work??  I read through all posts concerning Data Portal Create, and cannot seem to find the post you are referring to.  Thats why I posed the question regarding Project Tracker to simply display the Guid that is created for the new object.  Unfortunately still lost on this topic.  Will search Binding Source Component and hope for a good example.

thx

Don

dstarkey replied on Monday, October 23, 2006

I am using the Csla DataSource object to bind my web form to the bo.  It just seems that it will not display the default values instantiated in the DataPortal.Create Method.  I even tried (DetailsView1.DataBind()) after stepping through the code I saw it 1) set the default props 2) when I subsequently called DetailsView1.DataBind() - the details view still left me with blank input text boxes.  Is the "Csla Data Source" the binding source component that you are referring too?  If so, I am already using this control.

Don

Bayu replied on Monday, October 23, 2006

Hi,

Are you also handling the SelectObject event that is raised by the CslaDataSource?

If not, you should:
- handle the event
- in the event handler you will be provided with an event-argument of type Csla.Web.SelectObjectArgs
- set the BusinessObject property of this eventargs object to the one that you wish to bind to

If you are handling the event, then I have no clue why you are left with empty controls.

Bayu

dstarkey replied on Monday, October 23, 2006

I am using the select object correctly in my code.  The problem stems from the Insert part of the data source.  Let me elaborate, that the insert does work properly when I fill in the form and press the insert button. BUT the PROBLEM is not showing the default values on the initial Insert View.  Maybe its not even possible to display the default properties in an insert view????  This does seem rather odd?  Especially since, it would be nice to decouple the UI from the BO's (IE, setting controls in the Web Form to Default values, that I would much rather retrieve from the BO, thereby decoupling the UI from the BO.  Hope this makes sense, still do not know how to display the default values that are assigned in the DataPortal.Create Method.  Has anyone, displayed default properties of a BO to simplify a record insertion?????  Please help.

Thx Don

Copyright (c) Marimer LLC