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

[Solved] Can we identify which database table to grid?

6 Answers 125 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.
Nim
Top achievements
Rank 1
Nim asked on 26 May 2011, 04:16 PM
Hello,

I wonder for server-side-binding, how can we do something like:

   var tbl_1 = db.table1.AsEnumerable();
   var tbl_2 = db.table2.AsEnumerable();

    <%  Html.Telerik().Grid(Session["user_input"].toString() == "1"?tbl_1:tbl_2 )
                               .Name("testing")..... %>

Currently, the above codes do not work with an error message, which says there is no implicit conversion between the types of tbl_1 and tbl_2.


6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 27 May 2011, 07:11 AM
Hi Nim,

 You cannot do this because as the compiler suggests those type are not compatible with each other. Your code is equivalent to:

var tbl = Session["user_input"].toString() == "1" ? tbl_1: tbl_2;

which is also not possible.

You need to use two different grids:

<% if (Session["user_input"].toString() == "1" ) { %>

<%= Html.Telerik().Grid(tbl_1) %>

<% } else { %>
 
<%= Html.Telerik().Grid(tbl_2) %>


<% } %>

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
0
Nim
Top achievements
Rank 1
answered on 29 May 2011, 02:13 AM
Hello,

In our case, we have several views in the database.  They are almost the same except some logic of the query behind and a few columns.

Ideally, when different group access the page, we want to pick different view using the same grid.

If we use your suggestions, we will end up creating many grids for almost the same thing, which will likely require more maintenance work in long run.

Is there any plan to add new feature to Grid, which will allow different database tables/views to be shown at run-time?

Thank you for your consideration!

Nim
0
Atanas Korchev
Telerik team
answered on 30 May 2011, 07:41 AM
Hi Nim,

Does this work?

var t = Session["user_input"].toString() == "1" ? tbl_1: tbl_2;

If it doesn't then you won't be able to use the same with the Telerik Grid.

However if both tables are from the same base type you can easily do this:

IEnumerable<T> tbl = Session["user_input"].toString() == "1" ? (IEnumerable<T>)tbl_1: (IEnumerable<T>)tbl_2;

<%= Html.Telerik().Grid(tbl) %>

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
0
Nim
Top achievements
Rank 1
answered on 30 May 2011, 02:45 PM
Let me clarify my understanding.

About my question:

> "...Is there any plan to add new feature to Grid, which will allow different database tables/views to be shown at run-time?...",

I take your response as  "no".

Thank you for the reply.

Nim
0
Atanas Korchev
Telerik team
answered on 30 May 2011, 03:24 PM
Hello Nim,

 We are not sure how such a feature may work as the grid needs to know the type of the model during declaration time. It is either this or using <dynamic> or DataTable.

 It is the same as enabling var t = new List<Session["user_input"].toString() == "1" ? tbl_1: tbl_2>();

Best wishes,
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
0
Nim
Top achievements
Rank 1
answered on 30 May 2011, 03:27 PM
I see.  Thank you.
Tags
Grid
Asked by
Nim
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Nim
Top achievements
Rank 1
Share this question
or