Raddatepicker in Inline edit mode

2 posts, 0 answers
  1. shemein
    shemein avatar
    28 posts
    Member since:
    Mar 2014

    Posted 25 Aug 2014 Link to this post

    I have a radgrid in inline edit mode which has two raddatepicker in edit mode. when someone is typing some text that is not a date the datepicker will display an error sign inside the dateinput but when the person is clicking update button it updates the database by null. I want to cancel editing  when the error sign is in the inputdate box when the user click on update button. How can I do that?  my code is as below:
    protected void ToolkitList_ItemDataBound(object sender, GridItemEventArgs e)
    {
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
    GridEditableItem dataItem = (GridEditableItem)e.Item;
    RadDatePicker pickerdue = (RadDatePicker)dataItem["ToolkitDueDate"].Controls[0];
    pickerdue.ShowPopupOnFocus = true;
    pickerdue.DatePopupButton.Visible = false;
    pickerdue.Width = Unit.Pixel(80);


    RadDatePicker pickerboard = (RadDatePicker)dataItem["BoardMeetingDate"].Controls[0];
    pickerboard.ShowPopupOnFocus = true;
    pickerboard.DatePopupButton.Visible = false;
    pickerboard.Width = Unit.Pixel(80);


    }

    }

    protected void ToolkitList_UpdateCommand(object sender, GridCommandEventArgs e)
    {
    try
    {
    if (e.CommandName == RadGrid.UpdateCommandName)
    {
    GridEditableItem editedItem = e.Item as GridEditableItem;


    if (editedItem != null && editedItem.IsInEditMode)
    {
                                   
                            
                            int myUniqueId =
    Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][" ID"]);
    string labeloneText = string.Empty;
    string labeltwoText = string.Empty;
    RadDatePicker pickerdue = (RadDatePicker) editedItem["ToolkitDueDate"].Controls[0];
    RadDatePicker pickerboard = (RadDatePicker) editedItem["BoardMeetingDate"].Controls[0];

    if (!pickerdue.IsEmpty && !pickerboard.IsEmpty)
    {

    labeloneText = pickerdue.SelectedDate.ToString();
    labeltwoText = pickerboard.SelectedDate.ToString();
    bool success = _masterPage.ToolkitBo.UpdateDueandBoardDateForToolkit(myUniqueId,
    Convert.ToDateTime(labeloneText), Convert.ToDateTime(labeltwoText),
    _currentUser.FullName);

    // Rebind the toolkit list to reflect the changes.
    ToolkitList.Rebind();

    // If it was not successful, throw an error.
    if (!success)
    {
    throw new InvalidOperationException("Failed to add new due date.");
    }
    }

    // Update the toolkit's due date.
    if (pickerdue.IsEmpty && pickerboard.IsEmpty)
    {

    labeloneText = pickerdue.SelectedDate.ToString();
    labeltwoText = pickerboard.SelectedDate.ToString();
    bool success = _masterPage.ToolkitBo.UpdateDueandBoardDateForToolkit(myUniqueId,
    null, null, _currentUser.FullName);

    // Rebind the toolkit list to reflect the changes.
    ToolkitList.Rebind();

    // If it was not successful, throw an error.
    if (!success)
    {
    throw new InvalidOperationException("Failed to add new due date.");
    }
    }

    if (pickerdue.IsEmpty && !pickerboard.IsEmpty)
    {
    labeltwoText = pickerboard.SelectedDate.ToString();
    bool success = _masterPage.ToolkitBo.UpdateDueandBoardDateForToolkit(myUniqueId,
    null, Convert.ToDateTime(labeltwoText), _currentUser.FullName);

    // Rebind the toolkit list to reflect the changes.
    ToolkitList.Rebind();

    // If it was not successful, throw an error.
    if (!success)
    {
    throw new InvalidOperationException("Failed to add new due date.");
    }
    }
    if (!pickerdue.IsEmpty && pickerboard.IsEmpty)
    {
    labeloneText = pickerdue.SelectedDate.ToString();
    bool success = _masterPage.ToolkitBo.UpdateDueandBoardDateForToolkit(myUniqueId,
    Convert.ToDateTime(labeloneText), null, _currentUser.FullName);

    // Rebind the toolkit list to reflect the changes.
    ToolkitList.Rebind();

    // If it was not successful, throw an error.
    if (!success)
    {
    throw new InvalidOperationException("Failed to add new due date.");
    }
    }
    }
    }

    }
    catch (Exception err)
    {
                    
     }
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Aug 2014 in reply to shemein Link to this post

    Hi shemein,

    Please try to cancel the Update event of RadGrid if the RadDatePicker contains an invalid date. Please have a look into the below C# code snippet which works fine at my end.

    C#:
    protected void rgrdOrders_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridEditableItem editedItem = e.Item as GridEditableItem;
        //access the raddatepicker
        RadDatePicker editDate = editedItem.FindControl("rdatepickerStartDate") as RadDatePicker;
        //checking the condition whether datepicker contains invalid date or not
        if (editDate.InvalidTextBoxValue != string.Empty)
        {
            //invalid date then cancel the event
            e.Canceled = true;
        }
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top