I have a grid using an EditForm to edit the records. The EditForm has a RadComboBox (cmbDateChoice) and a RadDateTimePicker (dateParameter). Let's say the values in the RadComboBox are A, B, C. When the value is A, I want to enable the RadDateTimePicker, when it's B or C, I want to disable it. The grid has ALL rows set to be in edit mode via ItemCreated.
And this is the javascript function to manipulate the DateTimePicker:
When the combo box changes its index, all works perfectly. However, I can't find the right combination of code to get it to fire when the combobox is first initialized. In other words, if I come into the grid with a combobox value of B, I want the javascript to fire to change the DateTimePicker to disabled. I tried attaching the code to the OnClientLoad event on the combobox, but for some reason the DateTimePicker doesn't exist at that point (the $find returns null).
Any suggestions on how to go about this? Thanks.
| protected void gridParameters_ItemCreated(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem) |
| { |
| e.Item.Edit = true; |
| if (e.Item is GridEditFormItem) |
| { |
| Telerik.Web.UI.GridEditFormItem editForm = e.Item as Telerik.Web.UI.GridEditFormItem; |
| RadDateTimePicker dateParameter = (RadDateTimePicker)editForm.FindControl("dateParameter"); |
| RadComboBox cmbDateChoice = (RadComboBox)editForm.FindControl("cmbDateChoice"); |
| if ((cmbDateChoice != null) && (dateParameter != null)) |
| { |
| string fields = "<script type='text/javascript' language='javascript'>"; |
| fields += "function " + cmbDateChoice.ClientID + "_change() { "; |
| fields += "return ChangeDatePicker($find(\"" + cmbDateChoice.ClientID + "\"), $find(\"" + dateParameter.ClientID + "\"));"; |
| fields += "}"; |
| fields += "</script" + ">"; |
| gridParameters.Controls.Add(new LiteralControl(fields)); |
| cmbDateChoice.OnClientSelectedIndexChanged = cmbDateChoice.ClientID + "_change"; |
| } |
| } |
| } |
| } |
And this is the javascript function to manipulate the DateTimePicker:
| function ChangeDatePicker(choices, picker) |
| { |
| if (choices.get_value() == "A") |
| { |
| picker.get_dateInput().enable(); |
| $addHandler(picker.get_popupButton(), "click", picker._onPopupButtonClickDelegate); |
| if (window[picker.get_id()] != null) |
| { |
| picker._onTimePopupImageClickDelegate = window[picker.get_id()]; |
| $addHandler(picker.get__timePopupImage(), "click", window[picker.get_id()]); |
| } |
| } |
| else |
| { |
| picker.get_dateInput().disable(); |
| $removeHandler(picker.get_popupButton(), "click", picker._onPopupButtonClickDelegate); |
| $removeHandler(picker.get__timePopupImage(), "click", picker._onTimePopupImageClickDelegate); |
| window[picker.get_id()] = picker._onTimePopupImageClickDelegate; |
| picker._onTimePopupImageClickDelegate = null; |
| } |
| return true; |
| } |
When the combo box changes its index, all works perfectly. However, I can't find the right combination of code to get it to fire when the combobox is first initialized. In other words, if I come into the grid with a combobox value of B, I want the javascript to fire to change the DateTimePicker to disabled. I tried attaching the code to the OnClientLoad event on the combobox, but for some reason the DateTimePicker doesn't exist at that point (the $find returns null).
Any suggestions on how to go about this? Thanks.