This topic is locked
[SOLVED]

 Before SQL query event and user filtering

7/14/2016 11:04:18 AM
ASPRunner.NET General questions
Pete K author

I need to always filter (apply a where clause to) a list page. I expect this to work in addition to any user-specified filters and/or search phrases. However, I can't seem to get both working together. I am applying my filters in the "List page: Before SQL query" event.
On my first attempt, I tried:



strWhereClause = " (RegistrationDeadline > getdate()) and (Status=2) ";


This resulted in my query always being applied, but the user query being ignored. Next I tried:



strWhereClause = strWhereClause + " (RegistrationDeadline > getdate()) and (Status=2) ";


This had the opposite effect: Although initially my query worked, if the user applied a filter or search phrase, my where clause was subsequently ignored.
Am I doing something wrong? I considered both adding my additional where clause to the table's underlying SQL, or using the "After table initialized" event; however, this also restricts my view and edit pages in addition to the list page.
Any ideas?

Sergey Kornilov admin 7/14/2016

Yes, you still cannot use this event for this purpose. Need to use AftertableInit event. It provides the exact code yo need to use in order to add an additional WHERE clause:

http://xlinesoft.com/asprunnernet/docs/dynamic_sql_query.htm

Pete K author 7/15/2016



Yes, you still cannot use this event for this purpose. Need to use AftertableInit event. It provides the exact code yo need to use in order to add an additional WHERE clause:

http://xlinesoft.com...c_sql_query.htm


Thanks, but that also affects the view and edit pages as well, as I said above. I only want to apply my where clause to the list view.

Pete K author 7/15/2016

Okay, I came up with a work-around. Probably not the most elegant solution, but it works:



string pageX = HttpContext.Current.Request.Url.AbsolutePath;

if (pageX.Contains("list"))

{

query.addWhere("RegistrationDeadline > getdate() and Status=2");

}