mosArt
asked on
Formatting DateTime DataBinder Repeater problem
Got this in a repeater: <%# DataBinder.Eval(Container. DataItem, "ItemStartDate")%>
Outputs: 16.10.2006 00:00:00
Wants: 16.10.2006
Trying:
<% FormatDateTime(DateTime DataBinder.Eval(Container. DataItem, "ItemStartDate")) %>
//code below is in .cs file:
public DateTime FormatDateTime(DateTime date)
{
return date.ToShortDateString();
}
But I´m only getting: CS0029: Cannot implicitly convert type 'string' to 'System.DateTime'
...
Line 145: return date.ToShortDateString();
....
Can Anyone please tell me why?
Outputs: 16.10.2006 00:00:00
Wants: 16.10.2006
Trying:
<% FormatDateTime(DateTime DataBinder.Eval(Container.
//code below is in .cs file:
public DateTime FormatDateTime(DateTime date)
{
return date.ToShortDateString();
}
But I´m only getting: CS0029: Cannot implicitly convert type 'string' to 'System.DateTime'
...
Line 145: return date.ToShortDateString();
....
Can Anyone please tell me why?
* returing a string rather then datatime.
returning a string rather then datetime value.
returning a string rather then datetime value.
ASKER
It kinda worked, but it only got me half way there...
Can I send in the databinder to the method?
Trying:
<%FormatDateTime(DataBinde r.Eval(Con tainer.Dat aItem, "ItemID")); %>
Error:
CS0103: The name 'Container' does not exist in the current context
Is there another way?
Can I send in the databinder to the method?
Trying:
<%FormatDateTime(DataBinde
Error:
CS0103: The name 'Container' does not exist in the current context
Is there another way?
Hi, try to put a # there, see how it is going..
<%#FormatDateTime(DataBind er.Eval(Co ntainer.Da taItem, "ItemID")); %>
<%#FormatDateTime(DataBind
See here http://samples.gotdotnet.com/quickstart/aspplus/doc/webformssyntaxref.aspx#syntax
Rendering Code Syntax: <% %> and <%= %>
Code rendering blocks are denoted with <% ... %> elements, allow you to custom-control content emission, and execute during the render phase of Web Forms page execution.
Data Binding Syntax: <%# %>
Code located within a <%# %> code block is only executed when the DataBind method of its parent control container is invoked.
So when the rendering code syntax is running, the container is not there yet..so try to use the databinding syntax.
Rendering Code Syntax: <% %> and <%= %>
Code rendering blocks are denoted with <% ... %> elements, allow you to custom-control content emission, and execute during the render phase of Web Forms page execution.
Data Binding Syntax: <%# %>
Code located within a <%# %> code block is only executed when the DataBind method of its parent control container is invoked.
So when the rendering code syntax is running, the container is not there yet..so try to use the databinding syntax.
ASKER
Also good advice, but no sigar...
CS1502: The best overloaded method match for 'Default_aspx.FormatDateTi me(System. DateTime)' has some invalid arguments
...
Line 164: <%# FormatDateTime(DataBinder. Eval(Conta iner.DataI tem, "ItemStartDate"))%>
...
I cannot move the # infront of DataBinder.Eval, 'couse it have to be the first 'letter'.
CS1502: The best overloaded method match for 'Default_aspx.FormatDateTi
...
Line 164: <%# FormatDateTime(DataBinder.
...
I cannot move the # infront of DataBinder.Eval, 'couse it have to be the first 'letter'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
public String FormatDateTime(DateTime date)
{
return date.ToShortDateString();
}
You are getting error because return date.ToShortDateString(); is returing a string rather then datatime.