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

[Solved] Nice Easy Question...

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim Joslyn
Top achievements
Rank 1
Tim Joslyn asked on 14 Sep 2009, 09:59 PM
Hi,

I am sure that this is a nice easy question, been playing with the RadGrid for the past hour (newbie to Telerik) and cannot get it to work in the way I would expect with advanced data binding.

I am using LINQ for SQL, if I use a LINQDataSource on the page then everything works as expected however if I try to bind a custom data query in the code behind I am presented with an empty Grid (same query works ok with a normal GridView object).

In the little research I have done I have discovered that the NeedDataSource event should be used and in this scenario .DataBind is not necessary so my code looks as follows:

protected

 

void RadGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

 

{

 

    DataClassesDataContext MyData = new DataClassesDataContext();

 

 

    var LINQQuery = from MyObject in MyData.Objects

 

 


    select
new

 

    {

        Object_Type = MyObject.Object_Type.Name,

        Owner = MyObject.Owner_ID

      };

RadGrid.DataSource = LINQQuery;

}

On execution my RadGrid object shows no data (if I put the exact same query in the Page_Load event with DataBinf and assign it to a normal GridView then it works no problem.

I am sure I am missing something obvious but it's late so I need somebody to point it out.

Many thanks,

Tim 

1 Answer, 1 is accepted

Sort by
0
Tim Joslyn
Top achievements
Rank 1
answered on 15 Sep 2009, 06:45 AM
...which had a nice easy answer that I couldn't expect anybody to help with as I had not posted up the corresponding aspx code.

Issue was I had inadvertently set the autogenerate colums property to false so of course no data was displayed!
Tags
Grid
Asked by
Tim Joslyn
Top achievements
Rank 1
Answers by
Tim Joslyn
Top achievements
Rank 1
Share this question
or