Hello, how can I find a textbox control using the event OnBatchEditOpening?
I have created a column template.
<telerik:GridTemplateColumn HeaderText="Target" UniqueName="target" HeaderStyle-Width="360px"><HeaderStyle Width="360px" /><ItemTemplate><asp:Literal Text='<%# (Eval("target").ToString()) %>' runat="server" ID="literal_target"></asp:Literal></ItemTemplate><EditItemTemplate><telerik:RadTextBox runat="server" ID="txt_target" TextMode="MultiLine" Width="100%" /> </EditItemTemplate></telerik:GridTemplateColumn>
Thank you.
5 Answers, 1 is accepted
In order to get reference to the RadTextBox in the EditItemTemplate you can use the OnBatchEditOpened event. The handler would look similar to the following:
function batchEditOpened(sender, args) { var grid = sender; var batchEditManager = grid.get_batchEditingManager(); var masterTable = grid.get_masterTableView(); if (args.get_columnUniqueName() == "target") { var textBox = $telerik.findControl(args.get_cell(), "txt_target"); // add custom logic here }}Regards,
Viktor Tachev
Telerik
I want to access both Literal in ItemTemplate and Textbox in EditItemTemplate in this event. Is this possible?
My scenario is, I want to set hidden input(placed in Item Template) value on BatchEditCosed Event. I will get value from Dropdown in EditItemTemplate. This is because, I want to save all rows in grid on server side, instead of using BatchEditing update/save events. And EditItemTemplate control is not accessible on server side, on Button Click Event.
<telerik:GridTemplateColumn HeaderText="Category" HeaderStyle-Width="150px" UniqueName="Invoice_Category_ID" DataField="Invoice_Category_ID">
<ItemTemplate>
<input id="hdnCategory" type="hidden" runat="server" value="" />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="CategoryDropDown" DataValueField="Invoice_Category_ID"
DataTextField="Description" OnItemsRequested="CategoryDropDown_ItemsRequested" EnableLoadOnDemand="true">
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
You can check the sample at the end of this article for accessing controls from other cells:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/edit-mode/batch-editing/validation
You can also check the following code-library:
https://www.telerik.com/support/kb/aspnet-ajax/details/access-telerik-controls-on-client-side
In addition, I am attaching a sample RadGrid web site with accessing the value when it is present in the batch manager.
I hope this will prove helpful.
Regards,
Eyup
Progress Telerik
Hi Eyup,
Thanks for response, but this is not something I need. I can get reference of control placed in edititemtemplate or its value. But I cannot get reference of control placed in ItemTemplate. Like in example provided by me. I want to set value of hidden input control, when value in dropdown changes or when BatchEditClosed. Now I know, how to get value of "CategoryDropDown" placed in edititemtemplate but I can't get "hdnCategory" placed in ItemTemplate of same column. So I can store value for later use.
And I have a reason to do this. On server side, I want to access dropdown selected value for each row on button click.
<telerik:GridTemplateColumn HeaderText="Category" HeaderStyle-Width="150px" UniqueName="Invoice_Category_ID" DataField="Invoice_Category_ID">
<ItemTemplate>
<input id="hdnCategory" type="hidden" runat="server" value="" />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="CategoryDropDown" DataValueField="Invoice_Category_ID"
DataTextField="Description" OnItemsRequested="CategoryDropDown_ItemsRequested" EnableLoadOnDemand="true">
</telerik:RadComboBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
You can replace the HTML input element with a server-side HiddenField control and access it on server-side by using the gridItem.FindControl("MyHiddenFieldID") approach:
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hiddenfield(v=vs.110).aspx
Regards,
Eyup
Progress Telerik

