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

[Solved] Binding runtime generated columns to Grid

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rajesh Ramanathan
Top achievements
Rank 1
Rajesh Ramanathan asked on 23 May 2011, 05:56 AM
Hi,

In my scenerio, I have a dataTable which has runtime generated coulmns. I need to bind those columns to grid.
Below is my code, I can see the run time generated columns in header but not the data.

@{
    DataTable dt = new DataTable();
    dt = ViewBag.region;
     
}
<br />
<br />
<div>
    @(Html.Telerik().Grid<System.Data.DataRow>()
    .Name("Region")
             .DataKeys(dataKeys => dataKeys.Add(dt.Rows[0].ToString()))
    .Columns(columns =>
    {
        columns.Command(commands => commands.Select()).Title("Select");
        foreach (System.Data.DataColumn dataColumn in dt.Columns)
        {
            columns.Bound(dataColumn.DataType, dataColumn.ColumnName)
                .ClientTemplate("Data: <#= " + dataColumn.ColumnName + "#>");
        }
    }).Selectable()
        )


Can you please suggest the way out for it?

Thanks !!!

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 23 May 2011, 09:02 AM
Hello Rajesh,

It seems like you've missed the binding part of your grid configuration. For your convenience I am attaching sample app.

Regards,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rajesh Ramanathan
Top achievements
Rank 1
answered on 23 May 2011, 12:09 PM
Hi Nikolay,

Thanks for providing a sample code.

I tried to implement my code according to yours but didn't get any success. I am currently using MVC 3. 

 foreach (System.Data.DataColumn dataColumn in Model.Data.Columns)
                    {
}

Still facing the same error. I get the run time generated columns and corresponding data in Model.data, Runtime generated columns can be seen in the header as well but couldn't get the data in grid. 

is this related to client side and server side binding?

Looking forward to your reply.

Thanks !!!
0
Atanas Korchev
Telerik team
answered on 24 May 2011, 08:01 AM
Hello Rajesh Ramanathan,

 We are not sure what went wrong. Could you modify the attached project so it fails the same way as yours? 

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Rajesh Ramanathan
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Rajesh Ramanathan
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or