Change DropDownList DataSource on AddRow

1 reply. Last post: April 8, 2010 10:59 PM by Glenn Layaar
Tags :
  • New Discussion
  • New Question
  • New Product Feedback

Hi,

I found a way to do this, but I don't know if there's another approach to this.

I have a Grid with a DropdownList column (not WebCombo) and I need to swap the datasource for that column when adding a new row. Existing records need to display their corresponding text from the assigned datasource, but when adding I need the dropdown to point to another datasource... or simply use another dropdown editor hidden on the form. 

Basically, every entry on the datasource can be displayed for that column, but only a few may be added (based on permissions, etc). I'm doing this with the OnEnterEditMode method:

function webGridBeta_OnEnterEditMode(controlId, tblName, editObject) {
        if (editObject.ToCellObject().Name == "Status") {
            debugger;
            var editObj = editObject.element.value;
            var options = editObject.element.getElementsByTagName('option');
            var optionsLength = editObject.element.getElementsByTagName('option').length;
            optionsBackup = options;
            var ddlTemp = $get('<%=ddlStatusSwap.ClientID%>');
            var ddlOptions = ddlTemp.getElementsByTagName('option');
            var ddlOptionsLength = ddlTemp.getElementsByTagName('option').length;
            editObject.element.removeChild(options[2]);
            editObject.element.removeChild(options[1]);
            editObject.element.removeChild(options[0]);
            editObject.element.appendChild(ddlOptions[1]);
            editObject.element.appendChild(ddlOptions[0]);            
        }    
    }

 This ddlStatusSwap is being populated on Page_Load and I'm just moving its <Option> nodes to the dropdown the grid generates as I purge the "old" ones.

Is there a more efficient approach?

All times are GMT -5. The time now is 5:13 AM.
Previous Next