Thursday, June 5, 2008

GridView and Calendar Control

I was working with GridVeiw and Calendar controls for one of my projects. There I found one difficulty in showing date in calendar control when edit link is pressed it would give me
Specified cast is not valid
error; with much of searching I found a solution to it;

*Note* had to change '<' with LT and '>' with GT;

LT asp:Calendar ID="ActualEndDate" runat="server" Back Border
CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-
Fore Height="180px" SelectedDate='LT%# string.IsNullOrEmpty(Eval("ActualEndDate").ToString())?DateTime.MinValue:Eval("ActualEndDate") %GT'
Style="position: relative" Width="200px" GT

I changed '<%# Bind("ActualEndDate") %>' to above mentioned code and it worked for me,
as for update which was not working for some reason: all other fields would update except ActualEndDate; it would erase data and would show empty. So, I had to write in

protected void MyGridVeiw_RowUpdating(object sender, GridViewUpdateEventArgs e)

my custom update code and it seems to work fine. Hope this might help some other and I'm still testing if this solution would work properly.

Thanks for viewing my blog,


Tyampoo