1

I'm Trying to populate an ASPXComboBox using the InitNewRow event for inserting a new row, but I'm having problems binding the data to the ASPXComboBox.

I have used the CellEditorInitialize event for editing the row and it works fine, but the same principal on the InitNewRow event comes up with an 'object not set to an instance of an object' exception. However, the business logic function which is called returns a fully populated DataTable.

Could anyone help with this please.

tony
  • 309
  • 7
  • 23
  • can you please specify a grid’s markup and server-side event handlers? – Mikhail Jun 29 '11 at 21:15
  • please post your code in the InitNewRow event handler and also explain, whether you want to only set the editor's value or you also want to assign the editor's DataSource? – DevExpress Team Jun 30 '11 at 12:15
  • I have placed the code in the InitNewRow event and I tried to bind the e.NewValues with an ordered dictionary. However, I was to understand that the combo box would bind automatically. I want to set the comboboxes datasource – tony Jun 30 '11 at 14:31
  • When I do bind the data to the control using e.NewValues() it just returns the details of the item that has it has been bound with – tony Jun 30 '11 at 14:44

1 Answers1

0

If you want to set the comboBox's DataSource, use the CellEditorInitialize event for this purpose. If you need to determine when the grid works in the insert new row mode, use the ASPxGridView's IsNewRowEditing property. I.e. the code should be something like this:

protected void ASPxGridView1_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e) {
        ASPxGridView grid = sender as ASPxGridView;
        if(e.Column.FieldName == "SomeFieldName" && grid.IsNewRowEditing) {
            ASPxComboBox combo = e.Editor as ASPxComboBox;
            combo.DataSource = DataTable;
            combo.DataBindItems();
        }
    }

Does this approach work for you?

DevExpress Team
  • 11,338
  • 2
  • 24
  • 23
  • yes for when I'm editing a row, not creating a new one. I need this exact principal but for when i click on the new command button, so that when the user wants to add a new row to the gridview, they will be presented with a fully populated combo box – tony Jun 30 '11 at 17:15
  • OK, this approach should work for you. The DataTable variable in my code above should provide the required data for the editor. – DevExpress Team Jun 30 '11 at 18:35