This is a migrated thread and some comments may be shown as answers.

ItemDatabound even in Batch Edit mode of Rad Grid

7 Answers 556 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sunit
Top achievements
Rank 1
Sunit asked on 24 Mar 2014, 10:37 AM
I have a RadGrid in batch edit mode.
I want to bind drop down in Edit template column to some data from database when the row enters in Edit mode.
The data will be fetched based on a parameter passed from one of the column of  the selected row. So data that gets binded to dropdown is not static and can vary on row-to-row.

Ideal I would do this in ItemDatabound event of the asp.net GridView. But I noticed that in Batch Edit mode of RadGrid ItemDatabound doesn't get fired. 

How do I achieve this functionality in this case?
Thank you

7 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 27 Mar 2014, 11:48 AM
Hello Sunit,

The requirement that you have is difficult to accomplish, because as you have notice, the ItemDataBound event will not fire when you open a cell for editing. This is expected behavior, since Batch Edit mode is client-side oriented mode and the entire editing is handled on client-side.

What you could do to accomplish such behavior is to set the RadComboBox control EnableLoadOnDemand to true, handle the client-side OnBatchEditOpening and OnBatchEditOpened events of the grid, retrieve the value from the other column that you will need in order to populate the RadComboBox, save that value in a hidden field control for an example and on the server-side OnItemsRequested event of the combo box to retrieve that value from the hidden field.

For your convenience I have prepared a sample page with the above approach. Please give it a try and see if it meets your requirements.


Regards,
Konstantin Dikov
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Ángel
Top achievements
Rank 1
answered on 18 Sep 2014, 11:35 AM
Hello Konstantin,
I have the same scenario, I don't understand how can it be so tricky and tedious to bind a selectedvalue of a dropdown to the corresponding field on the datasource, especially with a radcombobox with load on demand, inside a radgrid in batchedit  mode.
It's the most common thing to work virtually in a grid and save changes to the database at the end like batch edit. And it's not efficient using a simple radcombobox because it's loaded for each row, even if you don't edit it. Moreover, loadondemand can filter and minimize the number of registers returned from the DB, So... It's necessary a much more elegant and simplier solution, is it possible?
Thanks
Angel.
0
Konstantin Dikov
Telerik team
answered on 20 Sep 2014, 03:10 PM
Hello Ángel,

An important thing that I must mention about Batch Editing, which will help you understand why RadComboBox with enable LoadOnDemand is not supported, is that each column has only one editor and that editor is placed in the currently edited row/cell. To put this in real scenario, imagine that you open a row for editing and you want to select a value from a RadComboBox with enabled LoadOnDemand. That combo box will request items from the server and will populate the combo box on the client-side. Now, when you finish with the editing of that row and you move to another row (or cell in another row), the RadComboBox will be the same as in the previous row and it will have the same items that were loaded the first time. Since that combo box is already populated, it will not request new items again.

Although it could be possible to have some custom logic for forcing a new request, this could not be added as a built-in functionality in Batch Editing and it is up to developer to find a suitable implementation (by handling different Batch Editing events and saving values in hidden fields).

Using Batch Editing provides great end user experience, but since the entire editing is done on client-side, it has its limitations.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brian
Top achievements
Rank 1
answered on 04 Nov 2014, 11:29 PM
Hello,

I tried implementing your example and data gets loaded as indicated. We don't use Neet_DataSource to bind as the grid is bound via ObjectDataSource on the .aspx page itself. Now, when I assign the value to the hidden field and make this call,

 $find("RadAjaxPanel1").ajaxRequest();

A post-back occurs and that retains the hidden field value (than if you'd do it without ajaxRequest), but now the drop-down doesn't show up - the flow stops there and the intended operation of loading the data using the RadComboBox1_ItemsRequested doesn't get called.

The dropdown arrow just flickers while postback and that's about it, the drop down doesn't expand and stay there. How can I over come this?
0
Konstantin Dikov
Telerik team
answered on 07 Nov 2014, 12:33 PM
Hello Brian,

From the provided information only it will difficult to determine what the actual issue is and what is causing it. You could however try to place the HiddenField control within the RadAjaxPanel and see if there is any difference in the behavior.

Once again I want to mention that having RadComboBox control with enabled LoadOnDemand functionality is not supported with Batch editing and there will be too many issues that could not be solved. With this in mind, please reconsider switching to another edit mode, which will work normally with LoadOnDemand functionality, related RadComboBox controls, etc.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brian
Top achievements
Rank 1
answered on 07 Nov 2014, 03:19 PM
Konstantin,

Thanks for your response. Indeed the "LoadOnDemand" on EditMode works as expected without any issues. The only "nice to have" feature we'd like to implement is to load data based on information selected/updated in another cell before navigating to this cell containing the drop-down. 

Is there any way other than setting the HiddenField in OnBatchEditOpened or OnBatchEditOpened? In this below code snippet, both the "Product" and "Instrument_Type" loads fine with the appropriate datasource based on their names. But I'd like to get the value of the selected cell value in [Product], when the "BindDataRow" server event is called on [Instrument_Type combo]. Is there any way to access the selected row's datakey values when we're in the BindDataRow within that same row? That will provide a cascading effect on the combo boxes based on value selected on the previous cell/combo.

Thanks.

<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" Skin="Telerik" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AutoGenerateColumns="False" Width="900px" Height="265px" DataSourceID="objDataSourceBA" OnBatchEditCommand="RadGrid1_BatchEditCommand" OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound" OnEditCommand="RadGrid1_ItemCommand" OnItemInserted="RadGrid1_ItemInserted" OnItemDeleted="RadGrid1_ItemDeleted" OnItemUpdated="RadGrid1_ItemUpdated">
 
<ValidationSettings EnableModelValidation="true" EnableValidation="true" CommandsToValidate="Update,InitInsert,Insert" />
 
<MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="False" DataKeyNames="Product,InvoiceInventoryTypeId,InvoiceInventoryType" DataSourceID="objDataSourceBA" HorizontalAlign="NotSet" EditMode="Batch">
 
<BatchEditingSettings EditType="Cell" OpenEditingEvent="Click" />
 
 <Columns>
 
<telerik:GridTemplateColumn DataField="Product" UniqueName="Product" HeaderText="Product" ItemStyle-Width="75px" HeaderStyle-Width="75px">
    <ItemTemplate>
        <asp:Label ID="lblProduct" runat="server" Width="60px" Text='<%# Eval("Product") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox ID="searchproduct" runat="server" AutoPostBack="false" Width="70px" EnableLoadOnDemand="true" OnItemsRequested="BindRowCombo">
        </telerik:RadComboBox>
        <asp:RequiredFieldValidator ID="searchproductValidator" runat="server" ControlToValidate="searchproduct" ErrorMessage="*Required" ForeColor="Red" Display="Dynamic"></asp:RequiredFieldValidator>
    </EditItemTemplate>
</telerik:GridTemplateColumn>
                                     
<telerik:GridBoundColumn DataField="Source" HeaderStyle-Width="50px" HeaderText="Source" ReadOnly="true" SortExpression="Source" UniqueName="Source"></telerik:GridBoundColumn>
    <telerik:GridTemplateColumn DataField="Instrument_Type" UniqueName="Instrument_Type" HeaderText="Instrument Type" HeaderStyle-Width="130px" ItemStyle-Width="130px">
        <ItemTemplate>
            <asp:Label ID="lblInstrumentType" runat="server" Width="130px" Text='<%# Eval("Instrument_Type") %>'> 
             </asp:Label>
        </ItemTemplate>
        <EditItemTemplate>
             <telerik:RadComboBox ID="searchinstrument_type" runat="server" AutoPostBack="false" Width="130px" EnableLoadOnDemand="true" OnItemsRequested="BindRowCombo"></telerik:RadComboBox>
        </EditItemTemplate>
</telerik:GridTemplateColumn>

function OnBatchEditOpening(sender, args) {
 
                //if (args.get_columnUniqueName() == "Instrument_Type") {
                    var hiddenField = document.getElementById("HiddenField1");
                    var row = args.get_row();
                    var idCell = sender.get_masterTableView()._getCellByColumnUniqueNameFromTableRowElement(row, "Product");
                    var id = sender.get_batchEditingManager().getCellValue(idCell);
                    hiddenField.value = id;
                    //$find("RadAjaxPanel1").ajaxRequest();
                //}
            }


protected void BindRowCombo(object sender, RadComboBoxItemsRequestedEventArgs e)
    {
        RadComboBox cmBox = sender as RadComboBox;
 
        DataTable dtLookup = null;
        string ControlName = cmBox.ID;
        string FieldName = string.Empty, FieldValue = string.Empty;
        string selectedProduct = HiddenField1.Value != null ? HiddenField1.Value : "";
 
            objCommon.InvoiceNum = Request.QueryString["InvNum"] != null ? Request.QueryString["InvNum"].ToString() : "";
            objCommon.InvDBId = Request.QueryString["InvDBId"] != null ? Request.QueryString["InvDBId"].ToString() : "";
 
            //if (selectedProduct.Length > 0) objCommon.Product = selectedProduct;
 
     dtLookup = objCommon.GetLookupData(FormName, ControlName, ref FieldName, ref FieldValue, userName, Location);
 
        if (dtLookup != null && FieldName.Length > 0)
        {
            cmBox.DataSource = dtLookup;
            cmBox.DataTextField = FieldName;
            cmBox.DataValueField = FieldValue.Length > 0 ? FieldValue : FieldName;
            cmBox.DataBind();
        }
    }

0
Konstantin Dikov
Telerik team
answered on 12 Nov 2014, 07:53 AM
Hello Brian,

If you change a value on client-side on a cell with Batch Editing, the only way for retrieving that change on server-side (without losing the changes) is through the RadAjaxManager/RadAjaxPanel using either a HiddenField control for storing the new value or by passing an argument to the manually fired AJAX request. For the second approach you could refer to the following help article:

Best Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Sunit
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Ángel
Top achievements
Rank 1
Brian
Top achievements
Rank 1
Share this question
or