where condition in code behind

paul carter asked on January 27, 2020 12:40

Hi, i have created a custom filter with two drop downs. I am using a where clause to perform the filtering on both drop downs

where += "DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID LIKE '%" + catagoryparent + "OR" + categorychild + "%')";

could you please confirm if i am using the correct syntax

Best regards

Recent Answers


Dragoljub Ilic answered on January 27, 2020 12:56

Hi Paul,

You SQL query syntax is bad after LIKE term. I'm not sure what you really try to accomplish, but you should try something like this: where += "DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID = " + catagoryparent + " OR CategoryID = " + categorychild + ")"

Best regards, Dragoljub

0 votesVote for this answer Mark as a Correct answer

paul carter answered on January 27, 2020 13:08

Hi, i copied the syntax from some code, always mess up with placement of quotes. I realised i needed another like after testing in sql server. Im just using the where to filter from two dropdowns. the first holds category parents and the second one contains filtered children based on the parents. Not too sure if best approach, as when i perform postback on the second dropdown it tends to clear the parent filter. would i be better inserting auto postback in the drop down controls ?

0 votesVote for this answer Mark as a Correct answer

Dragoljub Ilic answered on January 27, 2020 13:42

Hi Paul,

You can always bind data in the first dropdown based on the value selected from the second one, since the value in the first one must be parent of the category selected in second dropdown. Another way would be to pass data through ViewState, it's depends how and where your filter is placed (CMS or on public site).

Best regards, Dragoljub

0 votesVote for this answer Mark as a Correct answer

paul carter answered on January 27, 2020 14:40

Yes , that is correct, i am populating the second drop down using data binding and comparing with category parentID

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.