Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Grid > RadGrid Batch Update with Drop Down in Cell
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered RadGrid Batch Update with Drop Down in Cell

Feed from this thread
  • Rebecca Peltz avatar

    Posted on Jun 9, 2010 (permalink)

    I'm creating a sample program like your RadGrid batch update.  I need to put a dropdown (RadComboBox or asp dropdown).  When the javascript tries to put focus on a cell in the 'show editor' function it fails because the dropdown can't take focus.  Is it possible to use your batch edit technique with dropdowns in an editable cell?

    Here's where it fails (at colEditor.focus():
     function ShowColumnEditor() { 
                    editedCell = this
     
                    //hide text and show column editor in the edited cell 
                    var cellText = this.getElementsByTagName("span")[0]; 
                    cellText.style.display = "none"
                     
                    //display the span which wrapps the hidden checkbox editor 
                    if (this.getElementsByTagName("span")[1]) { 
                        this.getElementsByTagName("span")[1].style.display = ""
                    } 
                    var colEditor = this.getElementsByTagName("input")[0] || this.getElementsByTagName("select")[0]; 
                    //if the column editor is a form decorated select dropdown, show it instead of the original 
                    if (colEditor.className == "rfdRealInput" && colEditor.tagName.toLowerCase() == "select") colEditor = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(colEditor); 
                    colEditor.style.display = ""
                    colEditor.focus(); 
                } 


    Is there any other way to simulate editing a grid in batch mode with cell dropdowns?

  • Rebecca Peltz avatar

    Posted on Jun 9, 2010 (permalink)

    Forget this question - if I used asp:dropdown it works - it doesn't work with RadComboBox.

  • Rebecca Peltz avatar

    Posted on Jun 10, 2010 (permalink)

    Is it possible to get this code to work with RadComboBox - I know radcombobox renders several pieces.  If I wanted to turn on the appropriate pieces, what would be the javascript

    The code included in batch update example will turn on a 'select'. If I wanted to turn on all the pieces of a radcombo what would I need to do.

    Here is what turns on asp:dropdown
     var colEditor = this.getElementsByTagName("input")[0] || this.getElementsByTagName("select")[0];  
                    //if the column editor is a form decorated select dropdown, show it instead of the original  
                    if (colEditor.className == "rfdRealInput" && colEditor.tagName.toLowerCase() == "select") colEditor = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(colEditor);  
                    colEditor.style.display = "";  
                    colEditor.focus();  

    I can use asp:dropdown but would prefer to use radcombobox

  • Tsvetina Tsvetina admin's avatar

    Posted on Jun 16, 2010 (permalink)

    Hello Rebecca,

    You can replace the drop-down with a RadComboBox, only with a few changes made to the javascript from the demo.

    Here is the RadComboBox column declaration:
    <telerik:GridTemplateColumn UniqueName="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" HeaderStyle-Width="8%">
                        <ItemTemplate>
                            <asp:Label ID="lblUnitsInStock" runat="server" 
                            Text='<%# Eval("UnitsInStock") %>' />
                            <telerik:RadComboBox ID="ddlUnitsInStock" runat="server" 
                            DataTextField="UnitsInStock"
                            DataValueField="UnitsInStock" 
                            DataSourceID="SqlDataSource2" 
                            SelectedValue='<%# Bind("UnitsInStock") %>'
                            Style="display: none" Width="60px" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

    And here are the edited javascript functions:
    function ShowColumnEditor() {
                    editedCell = this;
      
                    //hide text and show column editor in the edited cell
                    var cellText = this.getElementsByTagName("span")[0];
                    cellText.style.display = "none";
                      
                    //display the span which wrapps the hidden checkbox editor
                    if (this.getElementsByTagName("span")[1]) {
                        this.getElementsByTagName("span")[1].style.display = "";
                    }
                    var colEditor = this.getElementsByTagName("div")[0] || 
                    this.getElementsByTagName("input")[0] || 
                    this.getElementsByTagName("select")[0];
                    //if the column editor is a form decorated select dropdown, show it instead of the original
                    if (colEditor.className == "rfdRealInput" && 
                    colEditor.tagName.toLowerCase() == "select"
                    colEditor = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(colEditor);
                    colEditor.style.display = "";
                    if (colEditor.tagName == "DIV") {
                        var combo = $find(colEditor.id);
                        combo.get_inputDomElement().focus();
                    }
                    else {
                        colEditor.focus();
                    }
                }

    function HideEditor(editCell, editorType) {
                    //get reference to the label in the edited cell
                    var lbl = editCell.getElementsByTagName("span")[0];
                      
                    switch (editorType) {
                        case "textbox":
                            var txtBox = editCell.getElementsByTagName("input")[0];
                            if (lbl.innerHTML != txtBox.value) {
                                lbl.innerHTML = txtBox.value;
                                editCell.style.border = "1px dashed";
      
                                StoreEditedItemId(editCell);
                            }
                            txtBox.style.display = "none";
                            break;
                        case "checkbox":
                            var chkBox = editCell.getElementsByTagName("input")[0];
                            if (lbl.innerHTML.toLowerCase() != chkBox.checked.toString()) {
                                lbl.innerHTML = chkBox.checked;
                                editedCell.style.border = "1px dashed";
      
                                StoreEditedItemId(editCell);
                            }
                            chkBox.style.display = "none";
                            editCell.getElementsByTagName("span")[1].style.display = "none";
                            break;
                        case "combobox":
                            var ddl = $find(editCell.getElementsByTagName("div")[0].id);
                            var selectedValue = ddl.get_value();
                            if (lbl.innerHTML != selectedValue) {
                                lbl.innerHTML = selectedValue;
                                editCell.style.border = "1px dashed";
      
                                StoreEditedItemId(editCell);
                            }                        
                            ddl.get_element().style.display = "none";
                        default:
                            break;
                    }
                    lbl.style.display = "inline";
                }


    function UpdateValues(grid) {
                    //determine the name of the column to which the edited cell belongs
                    var tHeadElement = grid.get_element().getElementsByTagName("thead")[0];
                    var headerRow = tHeadElement.getElementsByTagName("tr")[0];
                    var colName = grid.get_masterTableView().getColumnUniqueNameByCellIndex(headerRow, editedCell.cellIndex);
      
                    //based on the column name, extract the value from the editor, update the text of the label and switch its visibility with that of the column
                    //column. The update happens only when the column editor value is different than the non-editable value. We also set dashed border to indicate
                    //that the value in the cell is changed. The logic is isolated in the HideEditor js method
                    switch (colName) {
                        case "ProductName":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "QuantityPerUnit":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "UnitPrice":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "UnitsInStock":
                            HideEditor(editedCell, "combobox");
                            break;
                        case "UnitsOnOrder":
                            HideEditor(editedCell, "textbox");
                            break;
                        case "Discontinued":
                            HideEditor(editedCell, "checkbox");
                            break;
                        default:
                            break;
                    }
                }

    I hope that this achieves the functionality which you need.

    All the best,
    Tsvetina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

  • bberdel avatar

    Posted on Sep 9, 2010 (permalink)

    Is there a way to get this to work with RadDatetimePicker? 

  • Tsvetina Tsvetina admin's avatar

    Posted on Sep 10, 2010 (permalink)

    Hello Brian,

    There should be no problem with using a RadDateTime picker, as there are no specific requirements that would prevent it from working fine in this scenario. Still, do not hesitate to ask for help if you face any issues.

    Sincerely yours,
    Tsvetina
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • bberdel avatar

    Posted on Sep 10, 2010 (permalink)

    Can you assist with the ShowColumnEditor and Hide Code for the datetimepicker?

  • Tsvetina Tsvetina admin's avatar

    Posted on Sep 15, 2010 (permalink)

    Hi Brian,

    ShowColumnEditor() method can be updated in this way (the part related to the RadDateTimePicker and RadComboBox):
    function ShowColumnEditor() {
        editedCell = this;
        //hide text and show column editor in the edited cell
        var cellText = this.getElementsByTagName("span")[0];
        cellText.style.display = "none";
        //display the span which wrapps the hidden checkbox editor
        if (this.getElementsByTagName("span")[1]) {
            this.getElementsByTagName("span")[1].style.display = "";
        }
           
        var colEditor = this.getElementsByTagName("div")[0] || this.getElementsByTagName("input")[0] || this.getElementsByTagName("select")[0];
        colEditor.style.display = "";
        if (colEditor.tagName == "DIV") {
            var _Editor = $find(colEditor.id.replace("_wrapper", ""));
            if (colEditor.id.indexOf("_wrapper") != -1) {
                // DatePicker is Found
                _Editor.get_textBox().focus();
            }
            else
            {
                _Editor.get_inputDomElement().focus();
            }
        }
        else {
            colEditor.focus();
        }
    }


    As for the HideEditor() metohd, the javascript should look similar to that:
    function HideEditor(editCell, editorType) { 
        //get reference to the label in the edited cell 
        var lbl = editCell.getElementsByTagName("span")[0]; 
        switch (editorType) { 
          case:"datetimepicker"
               var dtPickerDIV = editCell.getElementsByTagName("div")[0];
                    var dtPickerID = editCell.getElementsByTagName("input")[0].id;
                    var dtPickerClientID = dtPickerID.replace("_dateInput_text", "");
                    var dtPicker = $find(dtPickerClientID);
                    if (lbl.innerHTML != dtPicker.get_textBox().value) {
                        lbl.innerHTML = dtPicker.get_textBox().value;
                        editCell.style.border = "1px dashed red";
                        StoreEditedItemId(editCell);
                    }
                    dtPickerDIV.style.display = "none";
                    break;
          //other cases 


    Sincerely yours,
    Tsvetina
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Rajesh avatar

    Posted on Sep 16, 2010 (permalink)

    Do we have any sample code of this batch update with ADVANCED binding (non-declarative)?  Please help. 

  • Tsvetina Tsvetina admin's avatar

    Posted on Sep 16, 2010 (permalink)

    Hello Rajesh,

    Could you please share what issues are you facing exactly in replacing declarative databinding with advanced data-binding?

    As an example you could use the code provided in this forum thread.

    Greetings,
    Tsvetina
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Rajesh avatar

    Posted on Sep 17, 2010 (permalink)

    I am looking for client side batch update including "insert" feature.  My grid will have cascaded dropdowns.  I am able to use advanced data binding for grid but need help in following areas.  Not sure if those are supported.
    I referred demo link http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/clienteditbatchupdates/defaultcs.aspx

    Example Scenario Grid: 
    ----------------------------
    Col1 - ProductID (Label)
    Col2 - ProductCategory (Dropdown)
    Col3 - ProductName (Dropdown)  (On product category selection this need to list items)
    Col4 - Other non-cascaded dropdown
    Col5 - Other non-cascaded dropdown


    NOW------->
    - How can I do multiple insert for new products?
    - How to provide the cascading effect to col3 based on col 2 selection from database?
    - I am creating custom lists for dropdowns and binding under _ItemCreated event. Since this event is being fired for each row, it make database calls for same data # of times.  Is there any way to not populate dropdowns and load only in cell edit mode?  This also increase page size since each drop down (hidden in regular mode) repeats under each row.

    Please help....Thanks

  • Tsvetina Tsvetina admin's avatar

    Posted on Sep 17, 2010 (permalink)

    Hi Rajesh,

    There are various forum threads discussing cascading RadComboBoxes in RadGrid. Here are a few links, I think that you will find the needed samples and isntructions there:
    Cascading comboboxes in RADGRID edit form
    Cascading combo boxes in edit form of RadGrid
    AJAX Cascadingdropdown inside Grid Edit

    You can also see a live sample of related RadComboBoxes in a RadGrid edit form here.

    In the scenario of batch updates you cannot directly perform multiple insert but you can, for example, add the needed number of empty records to the datasource the RadGrid is being bound to and then get them in edit mode.

    You can use the EnableLoadOnDemand property of RadComboBox, so they will fire their ItemsRequested event only when they are clicked/required to show their items.

    Sincerely yours,
    Tsvetina
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Rajesh avatar

    Posted on Sep 17, 2010 (permalink)

    I will try "insert" work around as you mentioned.
    Do you have any sample code where RadComboBox is using EnableLoadOnDemand inside the grid or any specific steps to implement?  If I get this working then half of the battle is won.

    Also, currently we are evaluating your product suite in trial mode.  Is there any phone support or better (customized) support we can get once we buy developer licenses?

    Thanks for your help.

  • Rajesh avatar

    Posted on Sep 20, 2010 (permalink)

    Please provide me more hints or sample code of using cascading dropdowns in Client side batch update scenario. We want to verify that we can accomplish our reqirement with telerik grid.  Thanks.

  • Tsvetina Tsvetina admin's avatar

    Posted on Sep 22, 2010 (permalink)

    Hello Rajesh,

    You can follow closely the logic for related RadComboBoxes from this online demo. The rest of it would be the same as for the other controls in the batch update.

    As for our support - currently we offer only email support and you can view what are the different options for customers at that address.

    Best wishes,
    Tsvetina
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Tiago avatar

    Posted on Jun 28, 2011 (permalink)

    Thanks! It worked pretty good with RadDatePicker for me, but im having some problems with RadMaskedTextBox. What are the necessary changes on the javascripts i must do?

    Thanks,
    Tiago Gerevini Yoshioka

  • Tsvetina Tsvetina admin's avatar

    Posted on Jul 4, 2011 (permalink)

    Hello Tiago,

    What exactly does not work in this scenario? You should have in mind that RadMaskedTextBox consists of four input elements, where the ID of the one that contains the value is "RadMaskedTextBox1_Value", and the ID of the one containing the display text is "RadMaskedTextBox1_text".

    Greetings,
    Tsvetina
    the Telerik team

    Consider using RadControls for ASP.NET AJAX (built on top of the ASP.NET AJAX framework) as a replacement for the Telerik ASP.NET Classic controls, See the product support lifecycle here.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Grid > RadGrid Batch Update with Drop Down in Cell