Technical support This forum is closed.
Version 1.x > Technical support > document template choice View modes: 
User avatar
Member
Member
Chameane - 12/23/2005 10:47:46 AM
   
document template choice
Hello,

I'm trying to make a product template a bit special...
In fact I've got 2 different types of products both types have severals common fields (name, photo, description) but the other parameters depends on the type of product (typeA has param1 and Param2, and typeB, param3,param4 and param5)

I need sort the products in different ways:

1. Alphabetical sort
2. Depending on the type of the product
3. Show only one type of product

I don't know with is the better way to do this...
If I create 2 different products, how can I do alphabetical sort? (in this sort, all the products are mixed)
If I create only one product with all the fields (name,photo,description,param1,param2,param3,param4,param5,type) then I've got no problem for the alphabetical sort but I don't know how to use diferent transformations for each product, and finally, with this solution, how can I display only typeA products?

Can anybody help me?

Thanks

User avatar
Guest
admin - 12/27/2005 6:29:20 PM
   
Re: document template choice
Hello,

if you need to display two types of documents (products) in the same listing, you will need to write a custom query. It will consist of two queries that will be "joined" using the UNION statement. Then, you can specify this query in the QueryDataList, QueryRepeater or QueryDataGrid control to display the content.

Please let me know if you need any further details.

Best Regards,

User avatar
Member
Member
Chameane - 12/30/2005 3:23:03 PM
   
Re: document template choice
Yes, thanks... I didn't noticed the QueryRepeater control!

Notwithstanding, this solution has a little problem...
For the alphabetical sort I needed to display it like this:

A

Aproduct1
Aproduct2

B

BProduct1

...

For solving the problem I've created a function in code behind wich uses ViewState[]... the problem is that althought 'Enable viewstate' was true, the viewstate var was reseted at every new row that was shown, so that I got something like this:

A

Aproduct1

A
Aproduct2

B
Bproduct1

...

Surfing into Google I've found this:

http://scottonwriting.net/sowblog/posts/2129.aspx

Maybe you could make something for your futures versions of the kentico CMS...

The solution I've done is:

Use a normal repeater with the item template defined in the same aspx page
in code-behind retrieve datasource as the SQL query I'd used in the QueryRepeater solution and bind the data.
As ViewState works fine xhen the item template is in the same page, this possibility shows the content as I needed.

Your CMSRepeater,CMSDatalist, QueryRepeater and also works great when you have not to touch code-behind in the ASCX file but due of the loadtemplate instruction, they're difficult to use in other cases.

Just one last question:
It's possible to call a function to retrieve the datasource of your QueryRepeater and display it with basic repeaters or datalist?
(By now I create my own connexion to the DataBase to retrieve infos)

SqlConnection cn = new SqlConnection();
cn.ConnectionString = ConfigurationSettings.AppSettings["CMSConnectionString"];
SqlDataAdapter da = new SqlDataAdapter(SQLString ,cn);
DataSet ds = new DataSet();
try
{
da.Fill(ds);
}
finally
{
cn.Close();
}


User avatar
Guest
admin - 12/30/2005 8:58:47 PM
   
Re: document template choice
You can retrieve content using Kentico CMS API. Here are two examples:

//example 1 - select nodes from the tree structure
TreeProvider tree = new TreeProvider();
DataSet nodesDS;
nodesDS = tree.SelectNodes("/products/nokia/%", TreePathTypeEnum.AliasPath,
"mobilestore.phone");

//example 2 - select data using the Data Engine and predefined queries
GeneralConnection cn = new GeneralConnection(Functions.GetConnectionString());
cn.DataConnection.Open();
DataSet ds = cn.ExecuteQuery("CMS.User.SelectByUserName", params);

I hope this helps.

Best Regards,

User avatar
Member
Member
Chameane - 1/2/2006 9:17:00 AM
   
Re: document template choice
thanks a lot

User avatar
Guest
admin - 1/3/2006 12:52:40 PM
   
Re: document template choice
Hello,

you can use the first solution and select/sort all documents (of both types) using a query like this:

SELECT name, photo, description
FROM PRODUCT_TYPE1
UNION
SELECT name, photo, description
FROM PRODUCT_TYPE2
ORDER BY name

Please let me know if you need any additional details.

Best Regards,