Answered by:
How can i add my own table to the default.aspx and hide some some table in the list?

Question
-
User781203069 posted
Hi, All, new to .net 3.5 sp1 and dynamic data
I had a dynamic data website and created the data context from database,
so the default.aspx listed all the table in the data context (tables in the dbml file)
my questions are:
1. How can i hide some tables i don't want, not allow people to see in list of default.aspx page
2. How can i add my own table in the list of default.aspx which is not in the database? do i need to create my scaffold table? if yes, please provide some code or example or link (as i remember i saw it some where on the web, can not find it now)
Thanks in advance
Friday, October 3, 2008 5:24 PM
Answers
-
User-330204900 posted
2. How can i add my own table in the list of default.aspx which is not in the database? do i need to create my scaffold table? if yes, please provide some code or example or link (as i remember i saw it some where on the web, can not find it now)Your main problem with (2) is that DD wont play with a table that is not in the model, if you wanted to deal with this table in a traditional ASP.Net way you could create some routing to facilitate that.
Adding this table to the list on the start page could be done like this:
protected void Page_Load(object sender, EventArgs e) { System.Collections.IList visibleTables = MetaModel.Default.VisibleTables; if (visibleTables.Count == 0) { throw new InvalidOperationException("There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages."); } var tables = from t in MetaModel.Default.VisibleTables select new MenuItem { ListActionPath = t.ListActionPath, DisplayName = t.DisplayName }; List<MENUITEM> menuTables = tables.ToList<MENUITEM>(); menuTables.Add(new MenuItem() { ListActionPath = "~/MyTable.aspx", DisplayName = "My Table" }); Menu1.DataSource = menuTables; Menu1.DataBind(); }
Hope this helps [:D]- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, October 4, 2008 5:11 AM -
User-330204900 posted
Sorry you will need this class as well:
public class MenuItem { public String ListActionPath { get; set; } public String DisplayName { get; set; } }
Hope this helps [:D]- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, October 4, 2008 5:26 AM
All replies
-
User-330204900 posted
Hi isme1111, have alook at my article here:
Part 4 - Limit Tables shown on Default page and List, Edit & Details etc.
where I limit the table based on a roles
Hope this helps [:D]
Friday, October 3, 2008 7:29 PM -
User-1005219520 posted
so the default.aspx listed all the table in the data context (tables in the dbml file)
my questions are:
1. How can i hide some tables i don't want, not allow people to see in list of default.aspx page
The easiest way to hide a table is to create a partials class and use the ScaffoldTable Attribute (setting it to false).
For example, the following class hides the Employee entity for the NW db. Make sure your partial class is surrounded by the namespace from you data model. If you create a LINQ to SQL web site, you don't get a namespace. You should also search for "public partial class TargetTableEntity" to verify you are using the correct name (you should find the TargetTableEntity in your data model).
[MetadataType(typeof(Employee_MD))] [ScaffoldColumn(false)] public partial class Employee { public class Employee_MD { [ScaffoldColumn(false)] [DataType(DataType.Date)] public object BirthDate { get; set; } [ScaffoldColumn(false)] [DataType(DataType.Date)] public object HireDate { get; set; } } }
Friday, October 3, 2008 8:34 PM -
User-1005219520 posted
deleted dupe
Friday, October 3, 2008 8:34 PM -
User781203069 posted
Thanks Steve, that is very helpful,
how about the second one? any hint?
Friday, October 3, 2008 8:59 PM -
User-330204900 posted
2. How can i add my own table in the list of default.aspx which is not in the database? do i need to create my scaffold table? if yes, please provide some code or example or link (as i remember i saw it some where on the web, can not find it now)Your main problem with (2) is that DD wont play with a table that is not in the model, if you wanted to deal with this table in a traditional ASP.Net way you could create some routing to facilitate that.
Adding this table to the list on the start page could be done like this:
protected void Page_Load(object sender, EventArgs e) { System.Collections.IList visibleTables = MetaModel.Default.VisibleTables; if (visibleTables.Count == 0) { throw new InvalidOperationException("There are no accessible tables. Make sure that at least one data model is registered in Global.asax and scaffolding is enabled or implement custom pages."); } var tables = from t in MetaModel.Default.VisibleTables select new MenuItem { ListActionPath = t.ListActionPath, DisplayName = t.DisplayName }; List<MENUITEM> menuTables = tables.ToList<MENUITEM>(); menuTables.Add(new MenuItem() { ListActionPath = "~/MyTable.aspx", DisplayName = "My Table" }); Menu1.DataSource = menuTables; Menu1.DataBind(); }
Hope this helps [:D]- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, October 4, 2008 5:11 AM -
User-330204900 posted
Sorry you will need this class as well:
public class MenuItem { public String ListActionPath { get; set; } public String DisplayName { get; set; } }
Hope this helps [:D]- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, October 4, 2008 5:26 AM -
User781203069 posted
Thanks Steve, that is very helpful . problem solved now :) thanks again
Saturday, October 4, 2008 5:37 AM