Dynamic Editable Grid - Object reference not set to an instance of an object

1 posts, 0 answers
  1. Rajesh
    Rajesh avatar
    1 posts
    Member since:
    Sep 2017

    Posted 22 Sep 2017 Link to this post

    Hi,

    I am creating columns programmatically based on the data return from database.

    For example:

    In Datatable i have following rows

    ColumnHeader      EditorType
    ABC                         TextBox
    XYZ                          DropDown
    AAA                          TextBox

     

    My Grid display format should be

    ABC                               XYZ                                          AAA

    Textbox Editor                Dropdown Editor                 Textbox Editor

     

    But i have an error in rgDynamic.Rebind()

    Note:

    DataBinding of dropdown editor done in ItemCreated event.

    protected void rgDynamic_PreRender(object sender, EventArgs e)
    {
        if (!rgDynamic.MasterTableView.IsItemInserted)
        {
            foreach (GridDataItem dataItem in rgDynamic.MasterTableView.Items)
            {
                if (dataItem is GridEditableItem)
                {
                    dataItem.Edit = true;
                }
            }
        }
        if (rgDynamic.MasterTableView.Items.Count > 0)
            rgDynamic.Rebind();
    }

    Stack Trace:

    System.NullReferenceException was unhandled by user code
      HResult=-2147467261
      Message=Object reference not set to an instance of an object.
      Source=Telerik.Web.UI
      StackTrace:
           at Telerik.Web.UI.GridDropDownListColumnEditor.BindComboBox(Object sender, EventArgs e)
           at System.Web.UI.Control.OnDataBinding(EventArgs e)
           at Telerik.Web.UI.RadComboBox.OnDataBinding(EventArgs e)
           at Telerik.Web.UI.RadComboBox.PerformSelect()
           at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
           at Telerik.Web.UI.RadComboBox.DataBind()
           at System.Web.UI.Control.DataBindChildren()
           at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
           at System.Web.UI.Control.DataBind()
           at System.Web.UI.Control.DataBindChildren()
           at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
           at System.Web.UI.Control.DataBind()
           at Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows)
           at Telerik.Web.UI.GridItemBuilder.InitializeItem(Int32 dataSourceIndex, String& nextItemHierarchicalIndex, Boolean& itemIsInEditMode)
           at Telerik.Web.UI.GridItemBuilder.CreateItems(GridGroupingContext group)
           at Telerik.Web.UI.GridTableView.CreateItems(IEnumerator enumerator, GridColumn[] columns, ControlCollection controls)
           at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)
           at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
           at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
           at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
           at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
           at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
           at Telerik.Web.UI.GridTableView.PerformSelect()
           at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
           at Telerik.Web.UI.GridTableView.DataBind()
           at Telerik.Web.UI.RadGrid.DataBind()
           at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason)
           at Telerik.Web.UI.RadGrid.Rebind()
           at WizardClient.rgDynamic_PreRender(Object sender, EventArgs e) in c:\------\release-40\WebMaster\Common\-----.aspx.cs:line 548
           at System.Web.UI.Control.OnPreRender(EventArgs e)
           at System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)
           at Telerik.Web.UI.RadCompositeDataBoundControl.OnPreRender(EventArgs e)
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Control.PreRenderRecursiveInternal()
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      InnerException:

     

Back to Top