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

Exception of type 'System.OutOfMemoryException' was thrown.

1 Answer 348 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ravi
Top achievements
Rank 1
Ravi asked on 21 Jun 2016, 11:04 AM

when i bind grid without  ItemDataBound it bind fine. But when i use it , then it show the Exception of type 'System.OutOfMemoryException' was thrown. error.

Here is my code

   protected void griddetails_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                griddetails.MasterTableView.RenderColumns[4].Display = false;
                griddetails.MasterTableView.RenderColumns[5].Display = false;
                griddetails.MasterTableView.RenderColumns[6].Display = false;
                griddetails.MasterTableView.RenderColumns[7].Display = false;

                griddetails.MasterTableView.RenderColumns[10].Display = false;
                griddetails.MasterTableView.RenderColumns[11].Display = false;
                griddetails.MasterTableView.RenderColumns[26].Display = false;
                griddetails.MasterTableView.RenderColumns[30].Display = false;
                griddetails.MasterTableView.RenderColumns[31].Display = false;
                griddetails.MasterTableView.RenderColumns[32].Display = false;

                //if (e.Item.RowIndex > -1)                                       // i comment this part but still not working
                //{
                RadComboBox ddlMT = new RadComboBox();
                ddlMT.ID = "ddlMT";
                   
                ddlMT.Filter = RadComboBoxFilter.Contains;
                ddlMT.DataSource = Bll.Bal_BindAllEmployeewithRole("ALL", Session["MTUseId"], e.Item.Cells[4].Text, e.Item.Cells[5].Text, "MT", null, null);
                ddlMT.DataTextField = "EmployeeName";
                ddlMT.DataValueField = "Empid";
                ddlMT.DataBind();
                e.Item.Cells[20].Controls.Add(ddlMT);

                RadComboBox ddlQA = new RadComboBox();
                ddlQA.ID = "ddlQA";
                   
                ddlQA.Filter = RadComboBoxFilter.Contains;
                ddlQA.DataSource = Bll.Bal_BindAllEmployeewithRole("ALL", Session["MTUseId"], e.Item.Cells[4].Text, e.Item.Cells[5].Text, "QA", null, null);
                ddlQA.DataTextField = "EmployeeName";
                ddlQA.DataValueField = "Empid";
                ddlQA.DataBind();
                e.Item.Cells[21].Controls.Add(ddlQA);

                RadComboBox ddlMT2 = new RadComboBox();
                ddlMT2.ID = "ddlMT2";
                  
                ddlMT2.Filter = RadComboBoxFilter.Contains;
                ddlMT2.DataSource = Bll.Bal_BindAllEmployeewithRole("ALL", Session["MTUseId"], e.Item.Cells[4].Text, e.Item.Cells[5].Text, "MT2", null, null);
                ddlMT2.DataTextField = "EmployeeName";
                ddlMT2.DataValueField = "Empid";
                ddlMT2.DataBind();
                e.Item.Cells[22].Controls.Add(ddlMT2);

                RadComboBox ddlQA2 = new RadComboBox();
                ddlQA2.ID = "ddlQA2";
                  
                ddlQA2.Filter = RadComboBoxFilter.Contains;
                ddlQA2.DataSource = Bll.Bal_BindAllEmployeewithRole("ALL", Session["MTUseId"], e.Item.Cells[4].Text, e.Item.Cells[5].Text, "QA2", null, null);
                ddlQA2.DataTextField = "EmployeeName";
                ddlQA2.DataValueField = "Empid";
                ddlQA2.DataBind();
                e.Item.Cells[23].Controls.Add(ddlQA2);

                RadComboBox ddlQC = new RadComboBox();
                ddlQC.ID = "ddlQC";
                  
                ddlQC.Filter = RadComboBoxFilter.Contains;
                ddlQC.DataSource = Bll.Bal_BindAllEmployeewithRole("ALL", Session["MTUseId"], e.Item.Cells[4].Text, e.Item.Cells[5].Text, "QC", null, null);
                ddlQC.DataTextField = "EmployeeName";
                ddlQC.DataValueField = "Empid";
                ddlQC.DataBind();
                e.Item.Cells[24].Controls.Add(ddlQC);

               
            }
            //}
        }
   
I think i am creating the control dynamic here it may be due to this. This code bind upto 971 records but after that it show error.

if there is another way to create it, tell me. I want to bind thru it server side not clientside bcoz it can't fullfill my need.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Jun 2016, 08:51 AM
Hi Ravi,

The ItemDataBound event is raised for every grid item, therefore, it is not suitable for such logic. Please define your entire grid during Page_Init and create ItemTemplates programmatically:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically#creating-template-columns-programmatically

For improving the overall performance with grid templates, you can check the explanation provided in the following post:
http://www.telerik.com/forums/radgrid-becomes-too-slow-when-binding-over-100-records#qxa2LUwVA0WYQpqmpwjrTg


I hope this will prove helpful.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Ravi
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or