I have a user control which contains a WHDG. This grid has a few basic properties set in the .aspx file. All of the columns, behaviors, editorproviders, etc... are added in the code behind.
Things work great the first time the page loads, however on a postback, such as a Save button click, the grid gets reloaded but all of the editors seem to get out of whack.
One post recommends applying the behaviors to the Grid.GridView, however this doesn't seem to work. When I try this, none of the EditingBehaviors appear to be getting created, even on the first page load.
Another post suggests that Editors/Behaviors added at runtime need to be reinstaniated on each postback. Following this approach doesn't seem to make any difference.
When I view source on the first grid and compare against the same grid after postback, everything seems to be there. However there is additional HTML that appears to be setting my editors to hidden. Which means something must be triggering the HierarchicalGridRender to emit this additional HTML. Either I am missing a property or something is null causing the HTML to get triggered during rendering.
...
I've stripped this example down in hopes an answer might be easier to come by.
BoundDataField boundDataField = new BoundDataField(true); boundDataField.DataFieldName = "UnitId"; boundDataField.Key = "UnitId"; boundDataField.Header.Text = ""; boundDataField.DataType = ColumnDataType.Int; boundDataField.Width = new Unit(150); boundDataField.Hidden = false; boundDataField.DataFormatString = "";
if (MyGrid.GridView.Columns[boundDataField.Key] == null) { MyGrid.GridView.Columns.Add(boundDataField); }
BoundDataField boundDataField2 = new BoundDataField(true); boundDataField2.DataFieldName = "Status"; boundDataField2.Key = "Status"; boundDataField2.Header.Text = "Status"; boundDataField2.DataType = ColumnDataType.String; boundDataField2.Width = new Unit(150); boundDataField2.Hidden = false; boundDataField2.DataFormatString = "";
if (MyGrid.GridView.Columns[boundDataField2.Key] == null) { MyGrid.GridView.Columns.Add(boundDataField2); }
//ACTIVATION MyGrid.Behaviors.CreateBehavior<Infragistics.Web.UI.GridControls.Activation>(); MyGrid.Behaviors.Activation.Enabled = true;
//EDITING CORE MyGrid.Behaviors.CreateBehavior<Infragistics.Web.UI.GridControls.EditingCore>(); MyGrid.Behaviors.EditingCore.Enabled = true; MyGrid.Behaviors.EditingCore.AutoCRUD = false; MyGrid.Behaviors.EditingCore.BatchUpdating = true; MyGrid.Behaviors.EditingCore.EnableInheritance = true;
//CELL EDITING MyGrid.Behaviors.EditingCore.Behaviors.CreateBehavior<Infragistics.Web.UI.GridControls.CellEditing>(); MyGrid.Behaviors.EditingCore.Behaviors.CellEditing.Enabled = true; MyGrid.Behaviors.EditingCore.Behaviors.CellEditing.EditModeActions.EnableOnActive = true; MyGrid.Behaviors.EditingCore.Behaviors.CellEditing.EditModeActions.EnableOnKeyPress = true; MyGrid.Behaviors.EditingCore.Behaviors.CellEditing.EditModeActions.MouseClick = EditMouseClickAction.Single;
//DEFINE DROPDOWN ITEMS List<DIYDropDownItem> items = new List<DIYDropDownItem>(); items.Add(new DIYDropDownItem("Status1", "A", false)); items.Add(new DIYDropDownItem("Status2", "M", false)); items.Add(new DIYDropDownItem("Status3", "D", false)); items.Add(new DIYDropDownItem("Status4", "I", false));
List<DropDownItem> ddi = new List<DropDownItem>();
foreach (DIYDropDownItem item in items) { ddi.Add(CreateDropDownItem(item.Text, item.Value, item.Selected)); }
//DEFINE DROPDOWN PROVIDER DropDownProvider dropDown = new DropDownProvider(); dropDown.ID = "DropDownProvider1"; dropDown.EditorControl.DisplayMode = Infragistics.Web.UI.ListControls.DropDownDisplayMode.DropDownList; dropDown.EditorControl.TextField = "Status"; dropDown.EditorControl.ViewStateMode = System.Web.UI.ViewStateMode.Enabled; dropDown.EditorControl.EnableViewState = true;
foreach (DropDownItem ddi2 in ddi) { dropDown.EditorControl.Items.Add(ddi2); }
//ASSIGN DROPDOWN PROVIDER TO GRID'S EDITORPROVIDERS COLLECTION MyGrid.EditorProviders.Add(dropDown);
//LINK EDITOR TO A COULMN VIA COLUMN SETTING EditingColumnSetting setting = new EditingColumnSetting(); setting.ColumnKey="Status"; setting.EditorID = "DropDownProvider1"; //ADD SETTING TO GRID MyGrid.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(setting);
//UPDATE BEHAVIORS TO ENSURE THEY ARE REFLECTED IN UI MyGrid.RefreshBehaviors();