ASPX templates
Version 4.x > ASPX templates > How to reload QueryDataList View modes: 
User avatar
Certified Developer 8
Certified Developer 8
bryan-bit-wizards - 8/11/2009 8:42:46 AM
   
How to reload QueryDataList
I have QueryDataList which is displaying properly. However, I would like to pass my page an id and reload the QueryDataList using that value. I have tried the following code, but cannot get the QuerDataList to reload properly.

Ex:
In ASPX:
<uc1:querydatalist runat="server" ID="qdl1" QueryName="[Query name]"
TransformationName="[Transformation name]" RepeatDirection="horizontal"
RepeatLayout="table" EnablePaging="True" PagingMode="querystring" PagerPosition="bottom"
PageSize="5" RepeatColumns="1" ResultsPosition="None" ShowEditDeleteButtons="False"
OrderBy="[Order by clause]" BackNextLocation="None"/>

In CS:
qdl1.WhereCondition = "[ColumnName] = '" + [New value] + "'";
qdl1.ReloadData();

When I use this, the QueryDataList is always empty after I "reload" it.

-Bryan


User avatar
Kentico Developer
Kentico Developer
kentico_zbysekn - 8/12/2009 4:40:05 AM
   
RE:How to reload QueryDataList
Hi Bryan,

I think that you should use rather control in this case, because webpart won't give you any advantages and there could be also problems with caching.

Before you are setting the WHERE condition in your code, please set the StopProcessing property to true - so the default data load is stopped, then set the WHERE condition, set the StopProcessing to false and then reload the data using ReloadData(true). This should avoid double loading and should solve your problem.

Best Regards,
Zbysek Nemec.

User avatar
Certified Developer 8
Certified Developer 8
bryan-bit-wizards - 8/12/2009 8:07:41 AM
   
RE:How to reload QueryDataList
Thank you for your response.

I solved ther issue by creating a QueryDataList control from the code behind, setting the properties dynanimcally, then adding it to ASP PlaceHolder.

placeholder.Controls.Clear();
//Create QDL w/ defaults
CMS.Controls.QueryDataList qdl = new CMS.Controls.QueryDataList();
qdl.StopProcessing = true;
qdl.QueryName = "[QueryName]";
qdl.TransformationName = "[TransformationName";
qdl.RepeatDirection = RepeatDirection.Horizontal;
qdl.RepeatLayout = RepeatLayout.Table;
qdl.EnablePaging = true;
qdl.PagerControl.PagingMode = CMS.Controls.PagingModeTypeEnum.QueryString;
qdl.PagerControl.PagerPosition = CMS.Controls.PagingPlaceTypeEnum.Bottom;
qdl.PageSize = 5;
qdl.RepeatColumns = 1;
qdl.OrderBy = "[Order By Clause]";
qdl.PagerControl.BackNextLocation = CMS.Controls.BackNextLocationTypeEnum.Split;
qdl.PagerControl.ShowFirstLast = false;

//Check if the list should be filtered
if (Request.QueryString["id"] != null)
{
if (Request.QueryString["id"].ToString() != "")
{
if (IsNumeric(Request.QueryString["id"].ToString()))
{
//Get the CMSType
GeneralConnection cn = ConnectionHelper.GetConnection();
DataSet ds = null;
object[,] parameters = new object[1, 3];
parameters[0, 0] = "[Paramater Name]";
parameters[0, 1] = Request.QueryString["id"].ToString();
ds = cn.ExecuteQuery("[Filtering query]", parameters);
if (ds.Tables[0].Rows.Count > 0)
{
qdl.WhereCondition = "[ColumnName] = '" + ds.Tables[0].Rows[0][FilteredValue].ToString() + "'";
}
}
}
}
//Finish creating QDL
qdl.StopProcessing = false;
qdl.DataBind();
placeholder.Controls.Add(qdl);


Thank you for your help!