Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Return no records for a datasource? View modes: 
User avatar
Member
Member
Boolean - 8/8/2012 3:56:22 PM
   
Return no records for a datasource?
Hi

I have a datasource that is pointing to an ascx file. In the ascx file I have a list of related IDs that are used to pull data from the CMS Tree. Not all documents have these related ID's, they are set by the user.

Inside the datasource it builds out a where statement. If the related IDs exist, the where statement says "Where ID = 1 OR ID = 2" etc. etc. But if no IDs are supplied, the where statement is empty, which causes ALL records to be returned.

What I would like to do is say "if document does not contain list of IDs, return 0 records to the datasource", but I can't figure out a way of doing this short of writing "Where 1=2" =)

Is there a way to manually set the datasource to return no records? I tried StopProcessing but it doesn't seem to work.

Thanks

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 8/9/2012 2:46:20 AM
   
RE:Return no records for a datasource?
Hello,

Regrettably, I am not quite sure how your setup looks like. How are you populating the datasource? Isn't it possible to simply empty the datasource? Which type of datasource are you using?

Best regards,
Boris Pocatko

User avatar
Member
Member
Boolean - 8/9/2012 9:53:55 AM
   
RE:Return no records for a datasource?
Hi Boris

The datasource is set to use the path ("/%"). My datasource .ascx file (CarTypeDataSource.ascx) then builds up a where statement that is the "this.srcElem.WhereCondition" of the datasource (So in the end it says get all documents under /% where carType = 1 OR carType = 2).

"Isn't it possible to simply empty the datasource"

That's the part I'm not sure of. I might be missing something very obvious =)

If I set this.srcElem.DataSource = null and leave my where statement blank, it still returns all documents under /% (probably because after running my CarTypeDataSource.ascx file it runs CMSQueryDataSource which does it's own data retrieval and databind). So that's the part I'm stuck on - How do you empty the datasource?

I could do something like set the path as a location I know doens't exist, or as per my first post enter a Where statement I know will never pass, but it feels a bit..hacky...to do that.

Thanks Boris.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 8/9/2012 9:59:41 AM
   
RE:Return no records for a datasource?
Hello,

I'm still a bit out of the context I think. Aren't you able to set the CMSBaseDataSource.DataSource property directly? Of course, the simplest workaround would be to change the where condition to something, which is always false, such as 1=2.

Best regards,
Boris Pocatko