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

Weird issue with grid needdatasource

1 Answer 8 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 23 Oct 2013, 06:12 PM
I have the following issue with my grid needdatasource method, can't figure out why this keeps happening and its killing me:

    void grid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        RadGrid grid = (RadGrid)sender;
        string id = grid.ID;
        DataTable current = (DataTable)HttpContext.Current.Session[int.Parse(id.Split(new string[] { "RadGrid" }, StringSplitOptions.RemoveEmptyEntries)[0])];
        grid.DataSource = current;
    }

If i go to the page directly no problems what so ever, everything works perfect,but if i try to navigate to that page from a different page, lets say using server.trasnfer or response.redirect, i keep getting this error:

Unable to cast object of type 'System.Int32' to type 'System.Data.DataTable'.

On this line, does anyone know why this would happen or how to fix it?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 28 Oct 2013, 01:33 PM
Hello Brad,

You can put a breakpoint on the DataTable accessing line and debug the project to see whether the returned object by the Session is a DataTable.

Hope this helps. Please keep us updated on the result.

Regards,
Eyup
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
Brad
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or