I have a RadGrid with EditMode="Batch". It has a template column. In this column (in the EditItemTemplate) is a RadComboBox with CheckBoxes="True".
What I need to do is pre-check the values that have been previously saved. I realize that there is really only "one" editor for the entire column, so I was wondering if there was some javascript (handling the BatchEditOpening maybe?) that could run through a comma separated list contained in a hidden field or something, and check the appropriate values when opening the cell for editing? I set the contents of the RadComboBox in the grid's PreRender event, so it's only done once.
Perhaps another option is to have the RadComboBox set with EnableLoadOnDemand="true" and handle the OnItemsRequested to reload and select the data, after it handles the OnClientDropDownOpening="ClearComboBox" with the following code:
The trouble with option #2 is that I'm not sure how to get any values for that particular row to set up in code-behind. So I don't know how to get the data from the database for that record. Also, this will make a call to the database every time they open the ComboBox.
Any thoughts?
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
CellSpacing
=
"0"
GridLines
=
"None"
AllowMultiRowEdit
=
"True"
AutoGenerateColumns
=
"False"
AllowAutomaticInserts
=
"False"
AllowAutomaticUpdates
=
"False"
OnNeedDataSource
=
"GridNeedDataSource"
OnPreRender
=
"GridPreRender"
>
<
MasterTableView
AllowSorting
=
"True"
EditMode
=
"Batch"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Id"
HeaderText
=
"Id"
UniqueName
=
"IdColumn"
Display
=
"False"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Test Values"
UniqueName
=
"TestValuesColumn"
ItemStyle-Width
=
"400px"
>
<
EditItemTemplate
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"TestValuesComboBox"
DropDownAutoWidth
=
"Enabled"
HighlightTemplatedItems
=
"True"
CheckBoxes
=
"True"
EnableCheckAllItemsCheckBox
=
"True"
>
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
<
BatchEditingSettings
OpenEditingEvent
=
"DblClick"
/>
</
MasterTableView
>
</
telerik:RadGrid
>
protected
void
GridPreRender(
object
sender, EventArgs e)
{
RadGrid grid = sender
as
RadGrid;
if
(grid !=
null
)
{
GridTableView masterTable = grid.MasterTableView;
var editor = masterTable.GetBatchEditorContainer(
"TestValuesColumn"
);
var comboBox = (RadComboBox)editor.FindControl(
"TestValuesComboBox"
);
comboBox.Items.Clear();
for
(
int
i = 1; i <= 10; i++)
{
RadComboBoxItem item =
new
RadComboBoxItem();
item.Text = i.ToString();
item.Value = i.ToString();
comboBox.Items.Add(item);
item.DataBind();
}
}
}
What I need to do is pre-check the values that have been previously saved. I realize that there is really only "one" editor for the entire column, so I was wondering if there was some javascript (handling the BatchEditOpening maybe?) that could run through a comma separated list contained in a hidden field or something, and check the appropriate values when opening the cell for editing? I set the contents of the RadComboBox in the grid's PreRender event, so it's only done once.
Perhaps another option is to have the RadComboBox set with EnableLoadOnDemand="true" and handle the OnItemsRequested to reload and select the data, after it handles the OnClientDropDownOpening="ClearComboBox" with the following code:
function
ClearComboBox(sender, args) {
if
(sender.get_items().get_count() == 0) {
return
;
}
else
{
sender.clearItems();
sender.requestItems(
"parameter"
,
true
);
}
}
The trouble with option #2 is that I'm not sure how to get any values for that particular row to set up in code-behind. So I don't know how to get the data from the database for that record. Also, this will make a call to the database every time they open the ComboBox.
Any thoughts?