SelectObject event

SelectObject event

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


jyjy posted on Friday, July 27, 2007

I have a aspx page with a FormView with an EditItemTemplate which consists of regular form elements such as text boxes and drop down lists.  When the page loads, I want to get a business object and bind them to the elements.

However, I don't know how to generate the select object event.

if (Session[""PO Number" != null)

     // I want generate the event and set the e. BusinessObject on my OnSelect(object sender, SelectObjectArgs e)

 

Please help.

RockfordLhotka replied on Friday, July 27, 2007

You don't generate the event, data binding generates the event.

What you need to do is tell the UI control bound to the data to refresh itself, and it will ask data binding for data, which will trigger the event. To do this, call the DataBind() method on the UI control (or on the page itself, though that may refresh too much data).

jyjy replied on Friday, July 27, 2007

I am having a hard time loading a data into my FormView elements.  Basically,

My FormView is in insert mode.  It looks like this.  Before this page is loaded, I have Session["PO Number"] = "PO123".  If you look at the bottom of Initialize(),

I have the following:

if (Session["PO Number"] != null)

{

FormView1.DefaultMode = FormViewMode.Edit;

//FormView1.DataBind();

}

So, my objective is to after the UI elements are initialized with items, I want to load a business obejct and have the values set automatically, but it's not working.  In my aspx file, I have

<%# Bind("DateString") %>

for each UI element.

Please help.

 

protected void Page_Load(object sender, EventArgs e)

{

if (IsPostBack)

{

}

else

{

Initialize();

}

}

protected void Initialize()

{

// Vendor

DropDownList ddlVendor = (DropDownList)FormView1.FindControl("ddlVendor");

Companies oCompanies = MySpace.SystemEngineering.Procure.Companies.GetCompanyList(2);

Vendors oVendors = MySpace.SystemEngineering.Procure.Vendors.GetVendors(0);

foreach (Company oCompany in oCompanies)

{

foreach (Vendor oVendor in oVendors)

{

if (oCompany.ID == oVendor.CompanyID)

ddlVendor.Items.Add(new ListItem(oCompany.ShortName, oVendor.ID.ToString()));

}

}

// Bill To and Ship To

DropDownList ddlBillTo = (DropDownList)FormView1.FindControl("ddlBillTo");

DropDownList ddlShipTo = (DropDownList)FormView1.FindControl("ddlShipTo");

oCompanies = MySpace.SystemEngineering.Procure.Companies.GetCompanyList(1); // 1 is a company type

foreach (Company oCompany in oCompanies)

{

ddlBillTo.Items.Add(new ListItem(oCompany.ShortName, oCompany.ID.ToString()));

ddlShipTo.Items.Add(new ListItem(oCompany.ShortName, oCompany.ID.ToString()));

}

// Status

DropDownList ddlStatus = (DropDownList) FormView1.FindControl("ddlStatus");

PurchaseOrderStatuses oStatuses = MySpace.SystemEngineering.Procure.PurchaseOrderStatuses.GetPurchaseOrderStatuses();

foreach (PurchaseOrderStatus oStatus in oStatuses)

ddlStatus.Items.Add(new ListItem(oStatus.Name, oStatus.ID.ToString()));

//CslaDataSource1.SelectObject += new EventHandler<Csla.Web.SelectObjectArgs>(OnSelect);

//CslaDataSource1.

if (Session["PO Number"] != null)

{

FormView1.DefaultMode = FormViewMode.Edit;

//FormView1.DataBind();

}

}

protected void OnSelect(object sender, Csla.Web.SelectObjectArgs e)

{

e.BusinessObject = PurchaseOrder.GetPurchaseOrder("PO123");

//FormView1.DataBind();

//e.BusinessObject.

//PurchaseOrder oPO = PurchaseOrder.GetPurchaseOrder("PO123");

//Csla.Data.DataMapper.Map(e.Values, oPO);

//e.RowsAffected = 1;

//oPO.Save();

//Session["PO Number"] = oPO.Number;

//Response.Redirect("LineItem.aspx", true);

}

 

RockfordLhotka replied on Friday, July 27, 2007

Initializing web controls in insert mode is not as easy as it should be. Apparently this is by design on the part of ASP.NET, but it is unfortunate...

You may try searching the forum, as there've been previous discussions on this (either with FormView or DetailsView) and people have come up with a couple different solutions.

You can also look at the PTWeb reference app (part of ProjectTracker), because I use one technique to address this with DetailsView. Not pleasant, but functional.

Copyright (c) Marimer LLC