Pass QueryString to nested repeater

Mark Elliott asked on January 14, 2015 00:32

I am trying to pass a QueryString value to the WHERE condition of a nested repeater but can not seem to get it to work. When I do this:

<script runat="server">
protected override void OnInit(EventArgs e) {
NestedRepeater.WhereCondition = "DATEDIFF(day, DocumentCreatedWhen, GETDATE()) <="+ Eval(<%#Request.QueryString["SearchDays"]%> );

I get an ugly error. I also tried using K# syntax {?SearchDays?} but that got me nowhere either. Any ideas?

Correct Answer

Brenden Kehren answered on January 14, 2015 04:24

Your syntax is incorrect in several places:

NestedRepeater.WhereCondition = "DATEDIFF(day, DocumentCreatedWhen, GETDATE()) <=" + Request.QueryString["SearchDays"];

A better solution would be to parse out your querystring into an integer since it is coming from user input

int qsValue = CMS.Helpers.ValidationHelper.GetInteger(Request.QueryString["SearchDays"], 0);
NestedRepeater.WhereCondition = "DATEDIFF(day, DocumentCreatedWhen, GETDATE()) <= " + qsValue.ToString();
0 votesVote for this answer Unmark Correct answer

Recent Answers

Mark Elliott answered on January 14, 2015 17:24

Thanks Brenden that works great. I thought I had tried writing it like that during one of my many permutations of trying to get this to work but I guess not. Thanks!

0 votesVote for this answer Mark as a Correct answer

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