Binding Exception Handling

2 posts, 0 answers
  1. Stephen Cossgrove
    Stephen Cossgrove avatar
    7 posts
    Member since:
    Nov 2009

    Posted 07 Jan 2010 Link to this post


    i have the following in a RadGrid:
    <telerik:GridTemplateColumn HeaderText="Duration" UniqueName="Duration"
                        <asp:Label runat="server" ID="lblConferredDate" Text='<%# Eval("ConferredDate") %>'></asp:Label> 
                        <telerik:RadDatePicker  ID="rdpConferredDate" runat="server" DateInput-EmptyMessage="No Date" DbSelectedDate='<%# Bind("ConferredDate") %>'
                        </telerik:RadDatePicker > 

    The issue is that when i try to bind to the editItemTemplate i get exception about the mindate. What i would like is that if a date is less than the mindate of the control then set the value to null or empty.

    Can anyone tell/show me how to handle bind exceptions? 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 Jan 2010 Link to this post

    Hello Stephen,

    You can check compare the DatePicker date and the mindate from code behind and set null values as shown below:
     protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
                GridEditableItem editItem = (GridEditableItem)e.Item; 
                RadDatePicker datePicker = (RadDatePicker)editItem.FindControl("rdpConferredDate"); 
                DateTime dt1 = (DateTime)datePicker.SelectedDate; 
                DateTime minDate = new DateTime(1998,1,1); 
                int check = DateTime.Compare(dt1,minDate); 
                if( check < 0) 
                    datePicker.SelectedDate = null

Back to Top