Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > CMSQueryDataSource - Doesn't Re-query On Postback? View modes: 
User avatar
Member
Member
Carly Lyddiard - 10/28/2009 6:21:23 PM
   
CMSQueryDataSource - Doesn't Re-query On Postback?
Hi guys

I'm using CMSQueryDataSource in some webparts and am having great difficulty getting it to re-query the database on postback (I've added a whereclause on postback and would like to rebind to it).

The postback is happening fine, the binding is being called, but it is not even attempting to hit the database (I've even deliberately put bad SQL in the WhereCondition but no error is thrown).

For example, for a "selected index changed" event (autopostback) a code fragment is:
----------------
Response.Write("The postback was successful: your new WhereCondition is:" + mainwhere);
dsCountries.ClearCache();
dsCountries.WhereCondition = mainwhere;
dsCountries.DataBind(); // (tried with and without this line)

country.Items.Clear();
country.DataSource = dsCountries.DataSource;
country.DataBind();
----------------

No errors are being thrown, the response.write is being called, everything "appears" to be happening correctly but the data source is simply not going back to the database even though the whereCondition has changed - it is just providing its previously loaded data.

I can't find any examples of coding with this control, and I'd prefer to use Kentico's Queries than hit the database directly (so my client can adjust the SQL easily in future).

Any ideas? Suggestions? Is this just a bug in the CMSQueryDataSource control?

I've also tried things like invalidateLoadedData, DisableFilterCaching, and others with no luck. Version 4.1, if that helps.

Any help would be greatly appreciated! :-)

Cheers,

Carly

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 11/5/2009 5:23:00 AM
   
RE:CMSQueryDataSource - Doesn't Re-query On Postback?
Hi Carly,

I would not recommend you to use CMSQueryDataSource as source for dropdownlist. It is suitable for BasicRepeater or BasicDataList but not for dropdownlist. You may use the datasource gained by ExecuteQuery – e.g.

public static DataSet CMS.SettingsProvider.SqlHelperClass.ExecuteQuery(
string queryName,
Object[,] parameters,
string where,
string orderBy
)


You may add the condition to e.g. Paga_Load method:


if (!IsPostBack)
{
DataSet ds = new DataSet();

country.Items.Clear();
ds = CMS.SettingsProvider.SqlHelperClass.ExecuteQuery(<query name>, null, null, null);
country.DataSource = ds;


country.DataTextField = <value>;
country.DataValueField = <value>;

country.DataBind();
}


and add code similar to this one in "selected index changed" event:


DataSet ds = new DataSet();

country.Items.Clear();
ds = CMS.SettingsProvider.SqlHelperClass.ExecuteQuery(<query name>, null, mainwhere, null);
country.DataSource = ds;


country.DataTextField = <value>;
country.DataValueField = <value>;


country.DataBind();



Best regards,
Helena Grulichova

User avatar
Member
Member
Carly Lyddiard - 11/17/2009 5:54:03 PM
   
RE:CMSQueryDataSource - Doesn't Re-query On Postback?
Ah, OK :-)

Thanks very much for that, Helena.

Carly