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

Validator for GridDateTimeColumnEditor

2 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 29 Aug 2011, 04:44 PM
Hi,

i'm adding validator through the ItemCreated for the datetime column. The grid is giving me
Unable to cast object of type 'System.Web.UI.WebControls.Panel' to type 'System.Web.UI.WebControls.TableCell'.

the following is my c# code.

 

 

GridDateTimeColumnEditor editorStartTime = (GridDateTimeColumnEditor)item.EditManager.GetColumnEditor("StartRunTimeColumn");

 

cell = (

 

TableCell)editorStartTime.SharedTimeView.Parent;

 

RequiredFieldValidator

 

 

Validator =

 

new RequiredFieldValidator();

 

editorStartTime.SharedTimeView.ID =

 

"StartRunTimeColumn";

 

Validator.ControlToValidate = editorStartTime.TextBoxControl.ID;

Validator.BackColor = System.Drawing.

 

Color.Red;

 

Validator.ErrorMessage =

 

"*";

 

cell.Controls.Add(Validator);

2 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 29 Aug 2011, 07:10 PM
this code works:
protected void rgEditOrder_ItemCreated(object source, GridItemEventArgs e)
{
    GridEditableItem geItem;
    GridDataItem gdItem;
    RadDatePicker rdpShipDate;
    GridDateTimeColumnEditor ceShipDate;
    TableCell tcShipDate;
    CustomValidator cvShipDate;
 
    if (e.Item.IsInEditMode)
    { }
    else
        return;
 
    if (e.Item is GridEditableItem)
    { }
    else
        return;
 
    geItem = (GridEditableItem)e.Item;
    rdpShipDate = (geItem["ShipDate"].Controls[0] as RadDatePicker);
    rdpShipDate.ClientEvents.OnDateSelected = "ship_date_selected";
    rdpShipDate.AutoPostBack = true;    
    rdpShipDate.SelectedDateChanged += rdpShipDate_SelectedDateChanged;
    txtShipDate.Value = rdpShipDate.ClientID;
 
    ceShipDate = geItem.EditManager.GetColumnEditor("ShipDate") as GridDateTimeColumnEditor;
    tcShipDate = (TableCell)ceShipDate.PickerControl.Parent;
    cvShipDate = new CustomValidator();
    cvShipDate.ID = "cvShipDate";
    cvShipDate.ControlToValidate = rdpShipDate.ID;
    cvShipDate.ServerValidate += ShipDate_OnServerValidate;
    cvShipDate.Text = "*";
    cvShipDate.ErrorMessage = "Item already ordered on this ship date";
    tcShipDate.Controls.Add(cvShipDate);
}
hope that helps
0
Accepted
Elliott
Top achievements
Rank 2
answered on 30 Aug 2011, 07:56 PM
Minh

cell = (TableCell)editorStartTime.SharedTimeView.Parent;

try instead

cell = (TableCell)editorStartTime.PickerControl.Parent;
Tags
Grid
Asked by
Minh
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Share this question
or