CslaDataSource, in order to get it to reassign the business object through the "select" (where one codes something like this: e.BusinessObject = myQuery.GetQueryResults()..), only gets triggered on non-postback page calls if I'm correct.
One way might be to go away from the CslaDataSource. Another might be to do a Server.Transfer to itself and then refer back to the calling page to get the criteria and then to facilitate the retrieval and assign e.BusinessObject to the newly retrieved object - since Server.Transfer will facilitate a postback obviously, it'll trigger that select code. (I use the latter technique myself when it comes to a maintenance form right now where various parts of the BO can be manipulated but must be fully valid before saving is possible).
In the case of what you're talking about, I would probably opt for the former approach (not use the CslaDataSource).
I too would be interested in knowing if something else can "rebind" to a new business object myself other than a non-postback page call. (In which case you'd just bind to an empty result set initially and rebind afterwards).
My two cents.
Chris
I'll give you an example of what I do for queries, and hopefully it'll help.
I have what is called a Query object. It's an editable root. I can request new queries, retrieve a saved one, delete one, etc. The Query object contains the information defining the query. What elements are part of my search both to show as criteria and as result set items (it's a data-centric search engine).
I have, on my Query object, an ExecuteQuery command. (I'm assuming you're using Csla 2.0 -- if not, since you're new, I'd recommend stepping up to it). On my Query object, I have an instance method on my Query object called Execute(). It will utilize the ExecuteQuery command to perform a server side activity that will construct the dynamic SQL and return a DataTable and such.
Within the ExecuteQuery command is where you'd invoke your stored procedure (instead of what I do in my case, where I'm invoking a command type other than a stored procedure). You'll note that my command assigns values for the QueryResults, and that the instance method Execute() returns this QueryResults. This is how my UI code will utilize the "return value" of the stored procedure, so to say.
So my instance method looks like this on my Query (BusinessBase<Query>):
/// <summary> /// Executes the Query, returning a DataTable. /// </summary> public QueryResults Execute(){
ExecuteQueryCommand executeCommand;executeCommand = DataPortal.Execute<
ExecuteQueryCommand>(new ExecuteQueryCommand(this)); return executeCommand.Results;}
And then the command looks like this:
/// <summary> public QueryResults Results
{
get
{
return _results;
}
}
public ExecuteQueryCommand(Query queryToExecute)
{
_query = queryToExecute;
}
protected override void DataPortal_Execute()
{
querySQL = <Dynamically constructed SQL>
<snip>
selectColumnsCommand = new SqlCommand(querySQL, connection);
legacyDataAdapter = new SqlDataAdapter(selectColumnsCommand);
connection.Open();
legacyDataAdapter.Fill(dt);
}
<snip>
executionTimeMS = ...execution time;
_results = new QueryResults(executionTimeMS, querySQL, dt);
}
}
Hope that helps.
You need to understand how Web Forms data binding is working - this isn't specific to CslaDataSource, but rather to the broader data binding infrastructure.
The data binding mechanism is very lazy - which is good, as it is an optimization feature. What happens is this: a UI control (grid, etc.) determines that it needs data, so it asks for that data from data binding, which asks the data control, which asks the data source.
In the case of CslaDataSource, that last step means that the select event is raised so you know to provide the requested data.
To cause data on a page to reload at any time, you need to tell the UI control (grid, etc.) that it needs new data. Typically this is done by simply calling that control's DataBind() method. That tells the control to rebind, which causes it to ask data binding for data, which asks the control, which (with CslaDataSource) raises the select event.
So, after you've retrieved your other data, and need to refresh the drop-down list or whatever, simply add code to invalidate the drop-down list's data and it will rebinding all by itself.
RockfordLhotka:To cause data on a page to reload at any time, you need to tell the UI control (grid, etc.) that it needs new data. Typically this is done by simply calling that control's DataBind() method. That tells the control to rebind, which causes it to ask data binding for data, which asks the control, which (with CslaDataSource) raises the select event.
That's very useful information, thank you.
I did have some problems last time when it calls the page_load it will populates the Gridview, however I found a trick no to trigger the SelectObject() event in csladatasource during the first load. In your Gridview, convert all fields to template fields. Setting all fields to template fields, you also dont need to set the DataKeyNames properties.
Cheers,
Glenn
Hi Frank,
If your GridView doesn't do anything, just simply displaying a set of results you can use ObjectDataSource.
Cheers,
Glenn
Copyright (c) Marimer LLC