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

[Solved] Issue with Sample Project

2 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 13 Aug 2013, 01:31 PM
I am working with the following sample project.

http://www.telerik.com/community/code-library/aspnet-ajax/grid/excel-look-and-feel-for-radgrid.aspx#tForumTop

I am receiving the following errors in the stack trace. I am using the code directly within a User Control. Any help would be great.

[NullReferenceException: Object reference not set to an instance of an object.]
   dsCloud.UserControls.SpreadSheetSample.get_GridSource() +497
   dsCloud.UserControls.SpreadSheetSample.RadGrid1_NeedDataSource(Object source, GridNeedDataSourceEventArgs e) +16
   Telerik.Web.UI.RadGrid.OnNeedDataSource(GridNeedDataSourceEventArgs e) +190
   Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +108
   Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) +253
   System.Web.UI.Control.LoadRecursive() +70
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Control.LoadRecursive() +189
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177

2 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 13 Aug 2013, 02:33 PM
I believe the problem is here.

private DataTable GridSource
    {
        get
        {
            Object obj = ViewState["GRID_SOURCE_SESSION_KEY"];
            if (obj != null)
            {
                return (DataTable)obj;
            }
            else
            {
                DataTable table = new DataTable();
                using (SqlConnection conn = new SqlConnection(ConnectionString))
                {
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    adapter.SelectCommand = new SqlCommand(SELECT_QUERY, conn);
                    conn.Open();
                    adapter.Fill(table);
                }
                DataColumn[] keys = new DataColumn[] { table.Columns["ID"] };
                table.PrimaryKey = keys;
                table.Columns["Prefix"].MaxLength = 5;
                ViewState["GRID_SOURCE_SESSION_KEY"] = table;
                return table;
            }
        }
        set
        {
            ViewState["GRID_SOURCE_SESSION_KEY"] = value;
        }
    }

This is an Azure project...could the use of "ViewState" cause this issue?

0
Angel Petrov
Telerik team
answered on 16 Aug 2013, 07:27 AM
Hi Michael,

Indeed it looks like the DataTable may not be persisted correctly. Have you tried debugging the code? Additionally I would recommend trying to use the user control in a normal website project. If the problem is not reproducible there this will surely indicate that the issue is environment related.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or