Last post Apr 29, 2008 10:59 PM by CaptainStarbuck
Jan 25, 2006 06:07 PM|jcasp|LINK
I've seen many posts where people are confused about the Calendar control not binding properly with the underlying data source. The symptoms are either that the value is not updated or that it's updated with the 1st day of the month selected.
The problem has to do with misuse of Bind() versus Eval() for certain Calendar properties. For example, consider the following common mistake:
runat="server" SelectedDate='<%# Bind("DateField") %>'
VisibleDate='<%# Bind("DateField") %>'></asp:Calendar>
Experienced developers will immediately detect the problem here. SelectedDate is properly defined using the Bind() method, but the VisibleDate should NOT be using Bind(), but Eval() instead as follows:
VisibleDate='<%# Eval("DateField") %>'></asp:Calendar>
The VisibleDate property defines the default current Month that should be display for the Calendar (note that the date portion is irrelevant here). If Bind() was used instead of Eval() for this value, then it can really throw you off with a strange binding
behavior. For example, if you select a different date from the current month being shown, then the change is NOT update to the table. This is because the VisibleDate property value ignores the date portion and the internal processing thinks the value did
not change. However, if you select a date from a different month, then the first date of that month will be updated. As you might have guessed, this is because the month portion of the value changed, so the change in value is detected and saved, but with
the 1st date of that month. All this happens while the true binding for the SelectedDate is ignored due to another "binding" for the VisibleDate property.
So, rather than scratching your head and searching for solutions, becareful not to bind the VisibleDate property, but use the proper Eval() method instead.
Jan 25, 2006 06:38 PM|StrongTypes|LINK
Jan 28, 2008 11:54 AM|sam_soumya|LINK
I think Eval() is used used, if we want to do any operation upon that value. Like <GridViwe: ...... commandargument=<%#Eval("Id")%> commandname=<%#Bind("Name")%>
Apr 29, 2008 10:59 PM|CaptainStarbuck|LINK
Ryan's link is a 404.
I chased down his blog to