locked
Add TableDescription to MetaTable RRS feed

  • Question

  • User-751080518 posted

    Hi.

    I would like to display table description for every table in my L2S model on first default page.

    What would be the best way to achieve that?

    Borut

    Tuesday, May 3, 2011 5:45 AM

Answers

  • User-330204900 posted
    <asp:GridView ID="Menu1" runat="server" AutoGenerateColumns="false" CssClass="DDGridView" RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6">
        <Columns>
            <asp:TemplateField HeaderText="Table Name" SortExpression="TableName">
                <ItemTemplate>
                    <%--<asp:DynamicHyperLink ID="HyperLink1" runat="server"><%# Eval("DisplayName") %></asp:DynamicHyperLink>--%>
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("DisplayName") %></asp:HyperLink>
                    <%# Eval("Description") %>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

    and then

    //var table = Global.DefaultModel.GetTable("Products");
    //Response.Redirect(table.GetActionPath(PageAction.Insert));
    
    System.Collections.IList visibleTables = Global.DefaultModel.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.");
    }
    //Menu1.DataSource = visibleTables;
    
    var menuData = from t in Global.DefaultModel.VisibleTables
                   select new
                   {
                       DisplayName = t.DisplayName,
                       Url = t.ListActionPath,
                       Description = t.Attributes.OfType<DescriptionAttribute>().FirstOrDefault() != null ? t.Attributes.OfType<DescriptionAttribute>().FirstOrDefault().Description : ""
                   };
    Menu1.DataSource = menuData;
    Menu1.DataBind();

    that should do it

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 5, 2011 8:35 AM

All replies

  • User3866881 posted

    Hi:)
    Sorry I didn't catch you clearly——What do you mean "Displaying Table Description"?

    Is that a columnName or something else?

    If you want to bind to the GridView, I think you can set the property Caption for the GridView.

    Wednesday, May 4, 2011 10:24 PM
  • User-751080518 posted

    No.

    On first page of dynamic data - default.asp, where it displays table names (DynamicHyperLinks in gridview) I would like to add another column to GridView - Table description, which would show long description of table.

    Table descritons I already have in resource file, next to Display name of tables.

    I tried with extended class of MetaTable, but no luck, Links no longer work.

    public class MetaTableWithDescription : MetaTable
    {
        /// <summary> 
        /// Initializes a new instance of the <see cref="MetaTableWithDescription"/> class. 
        /// </summary> 
        /// <param name="metaModel">The entity meta model.</param> 
        /// <param name="tableProvider">The entity model provider.</param> 
        public MetaTableWithDescription(MetaModel metaModel, TableProvider tableProvider) : base(metaModel, tableProvider) { }
        protected override void Initialize()
        {
            base.Initialize();
        }
        public string TableDescription { get; set; }
    }
    Thursday, May 5, 2011 1:05 AM
  • User-330204900 posted
    <asp:GridView ID="Menu1" runat="server" AutoGenerateColumns="false" CssClass="DDGridView" RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6">
        <Columns>
            <asp:TemplateField HeaderText="Table Name" SortExpression="TableName">
                <ItemTemplate>
                    <%--<asp:DynamicHyperLink ID="HyperLink1" runat="server"><%# Eval("DisplayName") %></asp:DynamicHyperLink>--%>
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("DisplayName") %></asp:HyperLink>
                    <%# Eval("Description") %>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

    and then

    //var table = Global.DefaultModel.GetTable("Products");
    //Response.Redirect(table.GetActionPath(PageAction.Insert));
    
    System.Collections.IList visibleTables = Global.DefaultModel.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.");
    }
    //Menu1.DataSource = visibleTables;
    
    var menuData = from t in Global.DefaultModel.VisibleTables
                   select new
                   {
                       DisplayName = t.DisplayName,
                       Url = t.ListActionPath,
                       Description = t.Attributes.OfType<DescriptionAttribute>().FirstOrDefault() != null ? t.Attributes.OfType<DescriptionAttribute>().FirstOrDefault().Description : ""
                   };
    Menu1.DataSource = menuData;
    Menu1.DataBind();

    that should do it

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 5, 2011 8:35 AM
  • User-751080518 posted

    It works!

    Thanks, again ... Smile

    Friday, May 6, 2011 7:45 AM