Specified cast is not valid ?

6 posts, 0 answers
  1. D.SRINIVASA
    D.SRINIVASA avatar
    34 posts
    Member since:
    Oct 2010

    Posted 24 Aug 2011 Link to this post


    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
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 24 Aug 2011 Link to this post

    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
  3. D.SRINIVASA
    D.SRINIVASA avatar
    34 posts
    Member since:
    Oct 2010

    Posted 24 Aug 2011 Link to this post

    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
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 24 Aug 2011 Link to this post

    Hello,

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


    let me know if any concern.


    Thanks,
    Jayesh Goyani
  5. D.SRINIVASA
    D.SRINIVASA avatar
    34 posts
    Member since:
    Oct 2010

    Posted 24 Aug 2011 Link to this post

    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



  6. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 24 Aug 2011 Link to this post

    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
Back to Top