This is a migrated thread and some comments may be shown as answers.

Error while adding child template to Master Template

2 Answers 69 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Subramanya
Top achievements
Rank 1
Subramanya asked on 21 May 2020, 02:43 PM

     I am getting a Object variable not set error while adding a child template to master template of grid view

here is my code

            {
                grddisplaygrid.DataSource = (DataTable)TransactionController.FetchObject("Itemdetails");
            }

           
           GridViewMultiComboBoxColumn tempmulticombo = (GridViewMultiComboBoxColumn)grddisplaygrid.Columns["BatchNo"];
            tempmulticombo.HeaderText = TransactionController.g_strbatchCaption == "" ? tempmulticombo.HeaderText : TransactionController.g_strbatchCaption;
            tempmulticombo = (GridViewMultiComboBoxColumn)grddisplaygrid.Columns["StockNo"];
            tempmulticombo.HeaderText = TransactionController.g_strStockNoCaption == "" ? tempmulticombo.HeaderText : TransactionController.g_strStockNoCaption;
            GridViewComboBoxColumn tempcombo = (GridViewComboBoxColumn)grddisplaygrid.Columns["SMGUid"];
            tempcombo.IsVisible = false;
            tempcombo = (GridViewComboBoxColumn)grddisplaygrid.Columns["UOM"];
            DataTable dttemp = GetUOmlist();
            tempcombo.DataSource = dttemp;
            tempcombo.DisplayMember = "UnitSymbol";
            tempcombo.ValueMember = "QBGUID";
            tempcombo.DropDownStyle = RadDropDownStyle.DropDownList;
            tempcombo.AutoCompleteMode = AutoCompleteMode.Suggest;
            #region item level Location
            if (TransactionController.g_intLocationenabled == 3)
            {
                tempmulticombo = (GridViewMultiComboBoxColumn)grddisplaygrid.Columns["LocationCd"];
                tempmulticombo.IsVisible = true;
                tempmulticombo.Width = 100;
                tempmulticombo.ReadOnly = false;
                tempmulticombo.HeaderText = TransactionController.g_strlocationCaption == "" ? tempmulticombo.HeaderText : TransactionController.g_strlocationCaption;
            }
            #endregion item level Location

            OverrideColumnVisibility();
            if (TransactionController.g_intDisplayImageinItemDisplaygrid > 0)
            {
                GridViewImageColumn colimage = (GridViewImageColumn)grddisplaygrid.Columns["ItemImage"];
                colimage.IsVisible = true;
            }
            templatesubdetails = new GridViewTemplate();
            templatesubdetails.AllowAddNewRow = false;
            templatesubdetails.AllowEditRow = false;
            templatesubdetails.AllowDeleteRow = false;
            templatesubdetails.ShowRowHeaderColumn = false;
            if (dtsubitemdetails.Columns.Count > 0) { dtsubitemdetails.Columns.Clear(); }
            dtsubitemdetails.Columns.Add("cStockNo", typeof(string));
            dtsubitemdetails.Columns.Add("cItemDesc", typeof(string));
            dtsubitemdetails.Columns.Add("cBatchNo", typeof(string));
            dtsubitemdetails.Columns.Add("cQty", typeof(decimal));
            dtsubitemdetails.Columns.Add("cUOM", typeof(string));
            dtsubitemdetails.Columns.Add("cItemGUID", typeof(string));
            dtsubitemdetails.Columns.Add("cBatchGuid", typeof(string));
            dtsubitemdetails.Columns.Add("cBOMItemGuid", typeof(string));
            dtsubitemdetails.Columns.Add("cRowsrlno", typeof(int));
            dtsubitemdetails.Columns.Add("cBOMQty", typeof(decimal));
            dtsubitemdetails.Columns.Add("BatchEnabled", typeof(int));
            dtsubitemdetails.Rows.Clear();
            templatesubdetails.DataSource = dtsubitemdetails;

            templatesubdetails.Columns["cItemGUID"].IsVisible = false;
            templatesubdetails.Columns["cRowsrlno"].IsVisible = false;
            templatesubdetails.Columns["cBOMQty"].IsVisible = false;
            templatesubdetails.Columns["cBatchGuid"].IsVisible = false;
            templatesubdetails.Columns["cBOMItemGuid"].IsVisible = false;
            templatesubdetails.Columns["BatchEnabled"].IsVisible = false;
            templatesubdetails.Columns["cStockNo"].HeaderText = "Stock No.";
            templatesubdetails.Columns["cStockNo"].Width = 100;
            templatesubdetails.Columns["cItemDesc"].HeaderText = "Description";
            templatesubdetails.Columns["cItemDesc"].Width = 120;

            templatesubdetails.Columns["cBatchNo"].HeaderText = "Batch Number";
            templatesubdetails.Columns["cBatchNo"].Width = 100;
            templatesubdetails.Columns["cBatchNo"].IsVisible = TransactionController.g_intbatchEnabled > 0 ? true : false;

            GridViewDecimalColumn deccolumn = (GridViewDecimalColumn) templatesubdetails.Columns["cQty"];
            deccolumn.HeaderText = "Qty.";
            deccolumn.Width = 70;
            deccolumn.DecimalPlaces = 3;
            deccolumn.FormatString = "{0:N3}";

            templatesubdetails.Columns["cUOM"].HeaderText = "Per";
            templatesubdetails.Columns["cUOM"].Width = 80;
            grddisplaygrid.MasterTemplate.Templates.Clear();
            grddisplaygrid.Relations.Clear();
           
            
           grddisplaygrid.MasterTemplate.Templates.Add(templatesubdetails);

 

getting the error while executing the above line of code. kindly help me to solve the issue.

           

2 Answers, 1 is accepted

Sort by
0
Subramanya
Top achievements
Rank 1
answered on 22 May 2020, 06:35 AM
The Issue has been resolved .actually the issue because i haven't initialized the object properly. 
0
Nadya | Tech Support Engineer
Telerik team
answered on 22 May 2020, 01:34 PM

Hello Subramanya,

I am glad that you managed to resolve the problem that you had. Do not hesitate to contact us if you have any other questions.

Regards,
Nadya
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
GridView
Asked by
Subramanya
Top achievements
Rank 1
Answers by
Subramanya
Top achievements
Rank 1
Nadya | Tech Support Engineer
Telerik team
Share this question
or