Hello,
I have a RadGrid with a UserControl as the EditForm template. There's a RadComboBox with LoadOnDemand enabled on the UserControl. RadComboBox has client-side SelectedItemChanged event handler defined to populate values of other controls on the same UserControl in the grid's insert or edit form.
Since there are 4 different grids that use the same UserControl, I've set up 4 different SelectedItemChanged event handlers for each grid's current edit/insert form - generating and registering it on the fly in the UserControl's Page_PreRender event:
The event handlers are invoked just fine. But the problem is that when when I try to access each of the grid's edit form, the master table view's edit items are blank (in GetCurrentFormItem()). get_insertItem returns an object just fine. :
Are there conditions where get_editItems called on the master table view return null? What is the condition that get_editItems is guaranteed to return somehting?
Thanks,
Makoto
I have a RadGrid with a UserControl as the EditForm template. There's a RadComboBox with LoadOnDemand enabled on the UserControl. RadComboBox has client-side SelectedItemChanged event handler defined to populate values of other controls on the same UserControl in the grid's insert or edit form.
Since there are 4 different grids that use the same UserControl, I've set up 4 different SelectedItemChanged event handlers for each grid's current edit/insert form - generating and registering it on the fly in the UserControl's Page_PreRender event:
if
(txtParentGridID.Text !=
string
.Empty)
{
string
cmbZipHandlerName = txtParentGridID.Text +
"_cmbZip_SelectedIndexChanged"
;
string
script =
"function "
+ cmbZipHandlerName +
"(sender, args) {"
+
"var grd = $telerik.findGrid('"
+ txtParentGridID.Text +
"', null);"
+
"ZipAutoFillCurrentEditForm(grd, args.get_item());"
+
"}"
;
// Set event handler
cmbZip.OnClientSelectedIndexChanged = cmbZipHandlerName;
// registering to the Page object works
ScriptManager.RegisterStartupScript(Page,
typeof
(Page), cmbZip.ClientID +
"_handler"
, script,
true
);
}
The event handlers are invoked just fine. But the problem is that when when I try to access each of the grid's edit form, the master table view's edit items are blank (in GetCurrentFormItem()). get_insertItem returns an object just fine. :
// These zip autofill related functions are separated in a script file
function
ZipAutoFillCurrentEditForm(grd, selectedItem) {
var
formItem;
formItem = GetCurrentFormItem(grd);
if
(formItem)
{
var
city;
var
state;
var
island;
var
county;
var
country;
city = FindInputInTemplateForm(formItem,
'txtCity'
);
state = FindInputInTemplateForm(formItem,
'txtState'
);
island = FindInputInTemplateForm(formItem,
'txtIsland'
);
county = FindInputInTemplateForm(formItem,
'txtCounty'
);
country = FindInputInTemplateForm(formItem,
'txtCountry'
);
FillZipFields(selectedItem, city, state, island, county, country);
}
}
// Get current form item of a grid
function
GetCurrentFormItem(grd) {
var
master = grd.get_masterTableView();
var
formItem;
if
(master.get_isItemInserted()) {
// insert mode
formItem = master.get_insertItem();
}
else
{
// @todo check Edit mode
// get_editItems() is blank
var
editItem = master.get_editItems()[0];
if
(editItem) {
formItem = editItem.get_editFormItem();
}
}
return
formItem;
}
/*
Looks for a HTML element (inputbox) for a given server control
- FormItem: HTML element of RadGrid's Insert/Edit form
- ServerID: Server-side Control ID
*/
function
FindInputInTemplateForm(formItem, serverID) {
if
(formItem !=
null
) {
var
inputs = formItem.getElementsByTagName(
"input"
);
for
(
var
i = 0; i < inputs.length; i++) {
var
input = inputs[i];
// test with city
if
(input.id.indexOf(serverID) < 0)
continue
;
if
(input.type && input.type ==
"text"
) {
return
input;
}
}
}
}
/*
Full all of the address fields that are dependent on zip code
- selected: selected item (RadComboBoxItem object)
- city, state, island, county, country: respective input element
*/
function
FillZipFields(selected, city, state, island, county, country) {
if
(selected !=
null
) {
var
attrs = selected.get_attributes();
city.value = attrs.getAttribute(
'City'
);
state.value = attrs.getAttribute(
'State'
);
island.value = attrs.getAttribute(
'Island'
);
county.value = attrs.getAttribute(
'County'
);
country.value = attrs.getAttribute(
'Country'
);
}
}
Are there conditions where get_editItems called on the master table view return null? What is the condition that get_editItems is guaranteed to return somehting?
Thanks,
Makoto