I’m missing something, how do I make this work?
var now = DateTime.Now;
string loadStartDate = Request.QueryString["sd"] == String.Empty ? now.AddMonths( -14 ).ToShortDateString();
string loadEndDate = Request.QueryString[ "ed" ] == String.Empty ? now.ToShortDateString();
Basically when the page loades if sd and/or ed is blank, then fill the date with my pre-defined stuff.
You are forgetting a
:and the part after it.The conditional operator has three parts:
Request.QueryString["sd"] == String.Empty)You are missing the false branch syntax and value.
I would write it as:
Note:
string.IsNullOrWhitespaceis new to .NET 4.0, so usestring.IsNullOrEmptyfor prior versions.