I've written the following code using the example in the docs for creating a grid in code. Can anyone tell me why I get a null reference error on the grid.Columns property? If anyone has any other tips for creating a grid in code which is connected to a data source control please let me know.
Thanks.
UltraWebGrid grid = new UltraWebGrid(); grid.DataSourceID = "employeeDS"; grid.Columns.Add(EmployeeFields.EmployeeId.Name, EmployeeFields.EmployeeId.Name); grid.Columns.Add(EmployeeFields.FirstName.Name, EmployeeFields.FirstName.Name); grid.Columns.Add(EmployeeFields.LastName.Name, EmployeeFields.LastName.Name); grid.Columns.Add(EmployeeFields.Title.Name, EmployeeFields.Title.Name); grid.Columns.Add(EmployeeFields.IsContracted.Name, EmployeeFields.IsContracted.Name); grid.Columns.Add(EmployeeFields.HourlyRate.Name, EmployeeFields.HourlyRate.Name); grid.Columns.Add(EmployeeFields.GuaranteedHours.Name, EmployeeFields.GuaranteedHours.Name); grid.Columns.Add(EmployeeFields.HourToPayIncrease.Name, EmployeeFields.HourToPayIncrease.Name); grid.Columns.Add(EmployeeFields.RateCode.Name, EmployeeFields.RateCode.Name); grid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes; grid.DisplayLayout.AddNewRowDefault.Visible = AddNewRowVisible.Yes; grid.DisplayLayout.AddNewRowDefault.View = AddNewRowView.Top;
OK, my fault. I solved this problem. I wasn't referencing the grid that I dropped onto the web form.
I would however still like to know if anyone has any tips for building a grid in code.