Last post Feb 16, 2011 09:04 AM by bereav
Feb 14, 2011 04:46 PM|bereav|LINK
I am trying to achieve this:
"I was searching for a sample or tutorial on how to build a ListView with it'sTemplates and Datasources programmatically but without success.I think of building a generic Viewer of data, but columns and datasource arnot known at design time, so they have to be build dynamically in code-behind.Does somebody know where to find something ?"I found posts of the same thing on the internet but no answer. I could find examples that programatically load already created user controls in the LayoutTemplate and/or ItemTemplate but that is not what I am trying to achieve.I even tried to add a table with a runat="server" type of html table in the LayoutTemplate and to change it from the code behind file, but I cannot find it in intelisense. So I could not programatically add any <td> elements in the "rowHeader" tr (see bellow).<LayoutTemplate> <table id="layOutTable" runat="server" border="0" cellpadding="6" cellspacing="0"> <thead> <tr id="rowHeader" runat="server"> </tr> </thead> <tbody> <tr id="itemPlaceholder" runat="server"/> </tbody> <tfoot> <tr> </tr> </tfoot> </table></LayoutTemplate>I am about to give up on the Listview and try it with a GridView instead.Does anyone know a solution to this ?
Feb 14, 2011 07:36 PM|postonoh|LINK
I have a question data that will be loaded what source will it be.
Feb 15, 2011 06:13 AM|bereav|LINK
The data source will be set from the web pages where the user control is used.
First data source option will be:
I plan to create a property or a method in the user control that will allow the consumer code (the code in the web page) to give a List<T> as datasource.
T is a generic type which is actually going to be restricted to a base class (BEntity). Then there will be custom objects (POCO) like Customer which inherits from BEntity that will be used when building a list of customers that will be feed in to the user
Second data source option will be:
A plane DataSet that will actually contain only one DataTable with the result of some SQL statement. This option will be used for cases when the user control will have to show some complex selection in the database invoving multiple joins from different
Then the user control will just look into the datatable and create columns in the LayoutTemplate of the listview for each column in the datatable.
After this is done, the user control will just databind the datasource to the layout.
Feb 15, 2011 08:13 PM|Decker Dong - MSFT|LINK
According to what you describe, I think the best choice for you at present, as to my limited knowledge, is to use Dynamic Data Templates with LINQ or EntityFramework. Because any other controls of data presentation, you should either assign the design codes,
or your design viewer or something else in advance. However, Dynamic Data will be reflected automatically according to your specific datasource as well as their types. So I recommand you to use this, have a try and if you have some other questions
For more about Dynamic Data, you can read at:
1) Here's the nice videos of Dynamic Data step-by-step:
2) Here's the nice samples for you to read at:
Feb 16, 2011 09:04 AM|bereav|LINK
Unfortunately I cannot use any of these LINQ or EF. I have to use some existing projects and eventyally I will get some simple DataSet with the results of whatever sql was executed.
I have to set this DataSet into some property of the user control and then show whatever data is in it.
I will give it a go with a GridView in the user control to which I can programatically add columns depeinding on what I find in the datatable and then just fill it in.
Thank you for the dinamic data recomandation !