I'm using the following code to create a WebCombo in a cell of my grid and it's not working. Nothing is displayed in the cell when editing. I think the only difference between my code and the example from the docs is that my combo is created in code instead of being defined on the aspx page. Here is my code, does anyone know why this doesn't work?
void employeeGrid_InitializeLayout(object sender, LayoutEventArgs e) { WebCombo crewTypeList = new WebCombo(); crewTypeList.DataTextField = CrewTypeFields.CrewType.Name; crewTypeList.DataValueField = CrewTypeFields.CrewTypeId.Name; crewTypeList.DataSource = ServiceManager.GetEmployeeManager().GetCrewTypes(); crewTypeList.DataBind(); e.Layout.Bands[0].Columns.FromKey("CrewType").EditorControlID = crewTypeList.UniqueID; e.Layout.Bands[0].Columns.FromKey("CrewType").ValueList.DisplayStyle = ValueListDisplayStyle.DisplayText; }
My first impression: your WebCombo isn't being added to your page, and thus doesn't exist on the client. Try adding the following line after you instantiate the control:
this.Form1.Controls.Add(crewTypeList);
You could also add it to the Controls collection of any container control on your page. Don't just add it to "this.Page.Controls" - it will end up outside the <form> element, and as an ASP.NET control it must be inside a form element.
I don't know what I'm doing wrong but this is not working for me. I get an error message saying the following.
The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases.
Here is the code that I'm using:
void employeeGrid_InitializeLayout(object sender, LayoutEventArgs e) { // WebCombo WebCombo crewTypeList = new WebCombo(); this.MasterForm.Controls.Add(crewTypeList); // Form control from master page. // The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases. crewTypeList.DropDownLayout.AutoGenerateColumns = false; crewTypeList.Editable = false; crewTypeList.DataTextField = CrewTypeFields.CrewType.Name; crewTypeList.DataValueField = CrewTypeFields.CrewTypeId.Name; crewTypeList.DataSource = ServiceManager.GetEmployeeManager().GetCrewTypes().DefaultView; crewTypeList.DataBind(); UltraGridColumn crewTypeColumn = e.Layout.Bands[0].Columns.FromKey("CrewType"); if (crewTypeColumn != null) { crewTypeColumn.AllowUpdate = AllowUpdate.Yes; crewTypeColumn.Type = ColumnType.Custom; crewTypeColumn.EditorControlID = crewTypeList.UniqueID; crewTypeColumn.ValueList.DisplayStyle = ValueListDisplayStyle.DisplayText; } }
I've seen this work before, though I don't recall if it was an ASP.NET 1.1 page or simply a stand-alone ASPX page (meaning no master page). A quick Google search is finding me a number of other people hitting similar errors when trying to dynamically add controls when a master page is involved.
Please test what happens when you put a Placeholder control on the page at design-time, and add the WebCombo to the Placeholder's Controls collection instead of to the Controls collection of the form.