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

RaddatePicker in inline editmode problem

1 Answer 47 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, 09:36 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 disable the update button when the error sign is in the inputdate box and oblige the user to correct the input text. 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
Konstantin Dikov
Telerik team
answered on 28 Aug 2014, 02:19 PM
Hello Shemein,

For achieving such validation on server-side you should get reference to the RadDatePicker in the GridEditableItem, available in the event arguments within the OnUpdateCommand event. Once you have reference to the RadDatePicker control you can use its InvalidTextBoxValue property to determine if an incorrect date was entered and if so, cancel the update command.

Following is a simple demonstration of such validation:
protected void FundingDocumentsGrid_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridEditableItem item = e.Item as GridEditableItem;
    RadDatePicker picker1 = item["ExpiryDate"].Controls[0] as RadDatePicker; // find the RadDatePicker
    string invalidValue = picker1.InvalidTextBoxValue; // Retrieve the invalid value
    if (!string.IsNullOrEmpty(invalidValue)) //if not null, cancel the update command
    {
        e.Canceled = true;
    }
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Calendar
Asked by
shemein
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or