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

Raddatepicker in Inline edit mode

1 Answer 203 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
shemein
Top achievements
Rank 1
shemein asked on 25 Aug 2014, 10:04 PM
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)
{
                
 }

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Aug 2014, 06:33 AM
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.
Tags
Calendar
Asked by
shemein
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or