This question is locked. New answers and comments are not allowed.
When I create an OA datasource through the wizard, and use it as the datasource for a grid, I am forced to select a particular table from my DB.
During run-time however, I'd like to be able to change the table to show its data in the grid. Can i do this by setting properties of the
During run-time however, I'd like to be able to change the table to show its data in the grid. Can i do this by setting properties of the
OpenAccessDataSource in the code-behind?
I tried something like:
OpenAccessDataSource1.TypeName =
"DataClasses.Person";
OpenAccessDataSource1.DataBind();
But this didn't work.
Suggestions?
3 Answers, 1 is accepted
0
Hello MWM,
This should work. What is happening? Did you define grid columns that are not matching the new objects? Can you send me some more info?
All the best,
Jan Blessenohl
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
This should work. What is happening? Did you define grid columns that are not matching the new objects? Can you send me some more info?
All the best,
Jan Blessenohl
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Stephen
Top achievements
Rank 1
answered on 12 May 2009, 05:56 PM
Hi
Was this fixed please as having same problem? - if so could you post solution found
Rgds
Stephen
Was this fixed please as having same problem? - if so could you post solution found
Rgds
Stephen
0
Hello Stephen,
to accomplish this you should firstly let the gird generate the columns automatically instead of specifying them in advance. This way when you change the TypeName of the DataSource the grid wont search for properties that are not members of the newly set class. Here is an example of how a grid should look like:
Another problem that comes from trying to set the TypeName dynamically(or any other property) is that the one that is already written in the aspx page will override the one set from code behind on each PostBack. Having this in mind you can set the TypeName from the code behind and display the new class in the grid, but if you have let say paging on, and you change a page than the code from the aspx page will be applied and it will override the one set from the code behind. A way to go around this is to save the TypeName in the session and applay it on every post back of the page. This way your TypeName will be saved even after reloading a page. Here is an example on implementing this in the code behind:
And here is how the data source contol looks like:
Note that the TypeName is initially set to Category but when you click on a button it is set to Order in the code behind and its saved in the session. Later on each Post Back the TypeName is applied so its not lost.
All the best,
PetarP
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
to accomplish this you should firstly let the gird generate the columns automatically instead of specifying them in advance. This way when you change the TypeName of the DataSource the grid wont search for properties that are not members of the newly set class. Here is an example of how a grid should look like:
| <asp:GridView ID="GridView1" runat="server" |
| DataSourceID="OpenAccessDataSource1" AllowPaging="True"> |
| </asp:GridView> |
| public partial class _Default : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (!Page.IsPostBack) |
| { |
| Session["TypeName"] = OpenAccessDataSource1.TypeName; |
| OpenAccessDataSource1.TypeName = (string)Session["TypeName"]; |
| } |
| OpenAccessDataSource1.TypeName = (string)Session["TypeName"]; |
| } |
| protected void Button1_Click(object sender, EventArgs e) |
| { |
| OpenAccessDataSource1.TypeName = "OpenAccessData.Order"; |
| Session["TypeName"] = OpenAccessDataSource1.TypeName; |
| } |
| } |
And here is how the data source contol looks like:
| <telerik:OpenAccessDataSource ID="OpenAccessDataSource1" runat="server" |
| ContextTypeName="" EnableDelete="True" EnableInsert="True" EnableUpdate="True" |
| ObjectContextProvider="OpenAccessData.ObjectScopeProvider1, OpenAccessData" |
| OrderBy="" TypeName="OpenAccessData.Category" Where="" > |
| </telerik:OpenAccessDataSource> |
All the best,
PetarP
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.