This is a migrated thread and some comments may be shown as answers.

Specified cast is not valid ?

5 Answers 316 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
D.SRINIVASA
Top achievements
Rank 2
D.SRINIVASA asked on 24 Aug 2011, 07:21 AM

Hi,
i am D.Srinivasa,

                       in my project i have a RadGrid to Display a Data from the DataBase, in my RadGrid i have a RadDatePicker Control to display a date from backend,  here enabled the maximum date condition in Raddatepicker,

the following coding is the condition for maximum date operation in RadDatePicker, it checks whether the database can have the data or not, if data is available then it sets the maximum date to that RadDatePicker,

it returns an error is Specified Cast in Not Valid..

Code Is : 

<telerik:GridTemplateColumn UniqueName="gridActStart" HeaderText="Actual Start" AllowFiltering="false" ItemStyle-HorizontalAlign="Center"><br>
 <
ItemTemplate><br>                     
 <
telerik:RadDatePicker ID="actstart" runat="server" MaxDate='<%#If((Eval("early_start_display") IsNot DBNull.Value), Convert.ToDateTime(Eval("early_start_display")), CType("10/10/2011", System.Nullable(Of DateTime))) %>' Width="100px" Calendar-ShowOtherMonthsDays="false" Calendar-ShowRowHeaders="false" DbSelectedDate='<%# Bind("actual_start") %>' DateInput-DateFormat="MM/dd/yyyy">                     
</
telerik:RadDatePicker><br>                       
</
ItemTemplate><br>                   
 </
telerik:GridTemplateColumn>

and the following attachment is the database for my application. How to resolve this problem,

Thank You,
D.Srinivasa

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Aug 2011, 09:47 AM
Hello,

Try with below code snippet.

<%# Eval("Description") == null ? DateTime.now : Convert.ToDateTime(Eval("early_start_display")) %>


Let me know its working or not.

Thanks,
Jayesh Goyani
0
D.SRINIVASA
Top achievements
Rank 2
answered on 24 Aug 2011, 10:09 AM
Hi
Jayesh Goyani
 

                          Thanks for Reply,
                          the above code is not working properly, it have some errors like null is not declared, end of statement, expression expected etc.

Thanks 
D.Srinivasa
0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Aug 2011, 10:48 AM
Hello,

MaxDate='<%# string.IsNullOrEmpty(Convert.ToString(Eval("StartDate"))) ? DateTime.Now : Convert.ToDateTime(Eval("StartDate")) %>' >


let me know if any concern.


Thanks,
Jayesh Goyani
0
D.SRINIVASA
Top achievements
Rank 2
answered on 24 Aug 2011, 10:58 AM
Hi,
Jayesh Goyani

                        Thanks for reply,
                         in this operation also we have some errors like end of statement and  The '?' character cannot be used here only,

Thanks 
D.Srinivasa



0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Aug 2011, 11:10 AM
Hello,

the code which was posted in last post works perfectly from my side.

Please check again and if You still have issue then see below code snippet.
if (e.Item is GridDataItem)
       {
           GridDataItem item = e.Item as GridDataItem;
           RadDatePicker RadDatePicker1 = item.FindControl("RadDatePicker1") as RadDatePicker;
           if (string.IsNullOrEmpty(Convert.ToString(item.GetDataKeyValue("StartDate"))))
           {
               RadDatePicker1.MaxDate = DateTime.Now;
           }
           else
           {
               RadDatePicker1.MaxDate = Convert.ToDateTime(item.GetDataKeyValue("StartDate").ToString());
           }
 
 
       }
<MasterTableView DataKeyNames="StartDate">

let me know if any concern.


Thanks,
Jayesh Goyani
Tags
ComboBox
Asked by
D.SRINIVASA
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
D.SRINIVASA
Top achievements
Rank 2
Share this question
or