Repeater Need Help with Where Condition

Kim Driggers asked on May 11, 2016 17:42

I have a repeater webpart that I want to list documents that have been added to our site in the last 7 days. I am having trouble with the where condition.

Can some tell me how I would enter the where condition (Brenden)? Thanks in advance for your assistance.

Correct Answer

Anton Grekhovodov answered on May 11, 2016 18:00

Hi, You can use this expression DocumentCreatedWhen >= dateadd(day, -7, convert(date, getdate()))

5 votesVote for this answer Unmark Correct answer

Recent Answers


Chetan Sharma answered on May 11, 2016 19:17

This is an alternative way.

DateTime.Now - Convert.ToDateTime(Eval("DocumentCreatedWhen"))).TotalDays <= 7

This should also work. You may change the sign <= accordingly exact need.

Cheers, Chetan

0 votesVote for this answer Mark as a Correct answer

Kim Driggers answered on May 11, 2016 19:28

I tried both and the option that Anton gave actually worked with what I'm attempting to do on the page. Thanks to both of you for such quick responses.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on May 11, 2016 19:42

I have used this in the past, right now its subtracting the year, but you could modify it for week...maybe something like below. Haven't confirmed the week one, but seems like it could work...

//for everything in the last year
Year(NewsletterDate) = Year(DateAdd(yy, -1, GetDate()))

//for everything in the last week
DATEPART( wk,NewsletterDate) = DATEPART( wk,DateAdd(wk, -1, GetDate()))
0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on May 12, 2016 08:22

Hi Chetan,

Your code won't work, because in repeater the where condition is converted to sql where expression, but your code is written on C#/K# syntax (you can insert K# here, but result of macro resolving in the where condition have to be sql expression). Also you use Eval method, which is allowed only in a repeater item template (transformation).

0 votesVote for this answer Mark as a Correct answer

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