Fill RadDropDownList in Grid with BatchEdit Mode

1 Answer 87 Views
DropDownList Grid
Bart
Top achievements
Rank 1
Bart asked on 27 Mar 2023, 12:51 PM

Hi,

I have the following grid:


<TELERIK:RADGRID ID="RadGridProductCharacteristics" runat="server" AutoGenerateColumns="false" AllowAutomaticUpdates="true" OnItemUpdated="RadGridProductCharacteristics_ItemUpdated" OnItemDataBound="RadGridProductCharacteristics_ItemDataBound" OnItemCommand="RadGridProductCharacteristics_ItemCommand" OnPreRender="RadGridProductCharacteristics_PreRender">
	<CLIENTSETTINGS AllowGroupExpandCollapse="true" />
	<MASTERTABLEVIEW DataKeyNames="CharacteristicID" GroupLoadMode="Client" CommandItemDisplay="Top" EditMode="Batch">
		<BATCHEDITINGSETTINGS EditType="Cell" />
		<GROUPBYEXPRESSIONS>
			<TELERIK:GRIDGROUPBYEXPRESSION>
				<GROUPBYFIELDS>
					<TELERIK:GRIDGROUPBYFIELD FieldName="ParentCharacteristicName" />
				</GROUPBYFIELDS>
				<SELECTFIELDS>
					<TELERIK:GRIDGROUPBYFIELD FieldName="ParentCharacteristicName" HeaderText="Parent Characteristic" />
				</SELECTFIELDS>
			</TELERIK:GRIDGROUPBYEXPRESSION>
		</GROUPBYEXPRESSIONS>
		<COLUMNS>
			<TELERIK:GRIDBOUNDCOLUMN HeaderText="Characteristic" DataField="CharacteristicName" ReadOnly="true" />
			<TELERIK:GRIDBOUNDCOLUMN UniqueName="CharacteristicValue" HeaderText="Value" DataField="CharacteristicValue" />
			<TELERIK:GRIDTEMPLATECOLUMN HeaderText="Color" UniqueName="CharacteristicColor" DataField="CharacteristicColor">
				<ITEMTEMPLATE>
					<%# Eval("CharacteristicColor") %>
				</ITEMTEMPLATE>
				<EDITITEMTEMPLATE>
					<TELERIK:RADDROPDOWNLIST runat="server" ID="RadDropDownListColor" />
				</EDITITEMTEMPLATE>
			</TELERIK:GRIDTEMPLATECOLUMN>
			<TELERIK:GRIDBUTTONCOLUMN UniqueName="ImageButtonDelete" HeaderText="Action" ButtonType="ImageButton" ImageUrl="~/Resources/Images/icon_delete.png" CommandName="Delete" />
		</COLUMNS>
	</MASTERTABLEVIEW>
</TELERIK:RADGRID>

I would like to fill the RadDropDownListColor so it is filled when the user clicks the cell to edit the value.

I checked this article: Column Editors and from there I derived the following code:


protected void RadGridProductCharacteristics_PreRender(object sender, EventArgs e)
{
	GridTableView masterTable = (sender as RadGrid).MasterTableView;
	RadDropDownList radDropDownListColor = masterTable.GetBatchColumnEditor("CharacteristicColor") as RadDropDownList;

	radDropDownListColor.DataSource = DBCom.GetHTMLColors();
	radDropDownListColor.DataTextField = "HTMLColorName";
	radDropDownListColor.DataValueField = "HTMLColorCode";
	radDropDownListColor.DataBind();
	radDropDownListColor.Items.Insert(0, new DropDownListItem("", "0"));
}

But still the variable radDropDownListColor is null.

What am I doing wrong?

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 30 Mar 2023, 10:35 AM

Hello,

The BatchEdit is a Client-Side (JavaScript-based) functionality of the Grid, therefore, interaction with the Grid must be done on the Client-Side. Normally using TemplateColumns is not recommended when using BatchEditing but it can be used for simple Templates. Such scenarios however need manual handling of the editing.

The following article describes the main aspects of Batch Editing: RadGrid Batch Editing Templates and Specifics.
The specifics when using templates in Batch editing are explained in the Working With Templates article.
In this case, you should use the Client-Side APIs of both the Grid and the DropDownList to set the values of the cell and editor. The following client-side events can be used for the purpose:

You can find sample implementation using these events in the Working With Templates article linked above. 

I hope this information will help you achieve the desired. Please let me know if any further questions come up.

Regards,
Doncho
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DropDownList Grid
Asked by
Bart
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or