You'll need to add a Page_Load and access the Parameters in code to set the
DefaultValue.
The other option is to use an ExpressionBuilder. You ASPX will look like
this:
<asp:ControlParameter ControlID="Calendar1" Name="DUEDATE"
PropertyName="SelectedDate" Type="DateTime"
DefaultValue='<%$ DateTimeNow:d %>' />
This is using an expression builder. It's syntax to execute code to do the
default assignment of that value when the ASP.NET parser creates the page
code from the ASPX. But this will require an expression builder class. You
can add a new .cs file to your App_Code folder that looks like this:
using System;
using System.Web.Compilation;
using System.Web.UI;
using System.CodeDom;
public class DateTimeNow : ExpressionBuilder
{
public static string GetNow(string param)
{
return DateTime.Now.ToString(param);
}
public override System.CodeDom.CodeExpression GetCodeExpression(BoundPropertyEntry
entry, object parsedData, ExpressionBuilderContext context)
{
CodeMethodInvokeExpression ex = new CodeMethodInvokeExpression(new
CodeTypeReferenceExpression(typeof(DateTimeNow)), "GetNow", new CodePrimitiveExpression(entry.Expression.ToString( ).Trim()));
return ex;
}
}
And then in web.config you'll need a new entry:
<compilation debug="true" defaultLanguage="C#">
<expressionBuilders>
<add expressionPrefix="DateTimeNow" type="DateTimeNow, __code" />
</expressionBuilders>
</compilation>
-Brock
DevelopMentor
http://staff.develop.com/ballen We are working on a calendar event list in ASP.NET 2.0 using VWDE.
On load we create a calendar control, and a pair of nested DataLists.
the outer DataList fills from a name list from SQL 2000 query. The
inner list takes the name from each item in the outer list, and
creates a task list for each person. On initial load, the task lists
are empty. We want to do is set a default value <%# DateTime.Now %>
for one of the parameters in the second query that fills the task
list.
Code Line:
<asp:ControlParameter ControlID="Calendar1" Name="DUEDATE"
PropertyName="SelectedDate" Type="DateTime" DefaultValue='<%#
DateTime.Now
%>' />
does not work. Neither does trying to assign a value in the code
black, as the control has not been created yet. We have also tried
inserting a code block inside the document just behind the control
creation, but it does not work.
If we need to change to a "code behind" page style that is ok, but I'd
rather try to keep in the overall .NET 2.0 framework defaults.
TIA
Z