Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1070
Building grid in code
posted

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;

 

Parents
No Data
Reply
  • 1070
    Verified Answer
    posted

    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.

Children
No Data