locked
Get table description from VisibleTables on Default.apsx page. RRS feed

  • Question

  • User-647007878 posted

    Hello.

    I have ASP.NET 4 Dynamic Data Site.

    I would like to set a tooltip property with table description in a HyperLink control on Default.apsx page.

    I have used MetaTableExtensions class:

            public static string GetDescription(this MetaTable table)
            {
                return ((DescriptionAttribute)table.Attributes[typeof(DescriptionAttribute)]).Description;
            }

    On Default.aspx page there is only MetaModel.Default.VisibleTables that is binded to GridView. For example, on List.apsx page i am be able to get description by code MyNamespace.Classes.MetaTableExtensions.GetDescription(table).

    What do you think, how can i get my description on the Default.aspx page?

    Thank you.

    Tuesday, February 7, 2012 1:00 AM

Answers

  • User-330204900 posted

    your problem is you cannot get acces tot he table from the page so what I have done is:

    <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:HyperLink 
                        ID="HyperLink1" 
                        runat="server" 
                        ToolTip="<%# Eval("Description") %>" 
                        NavigateUrl="<%# Eval("ListActionPath") %>"><%# Eval("DisplayName"%></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    then in the code behind

    protected void Page_Load(object sender, EventArgs e)
    {
        var visibleTables = from t in Global.DefaultModel.VisibleTables.ToList()
                            select new
                                {
                                    DisplayName = t.DisplayName,
                                    ListActionPath = t.ListActionPath,
                                    Description = t.GetDescription()
                                };
    
    
        if (visibleTables.Count() == 0)
        {
            throw new InvalidOperationException("There are no accessible tables...");
        }
        Menu1.DataSource = visibleTables;
        Menu1.DataBind();
    }
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 7, 2012 1:26 PM

All replies

  • User-330204900 posted

    your problem is you cannot get acces tot he table from the page so what I have done is:

    <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:HyperLink 
                        ID="HyperLink1" 
                        runat="server" 
                        ToolTip="<%# Eval("Description") %>" 
                        NavigateUrl="<%# Eval("ListActionPath") %>"><%# Eval("DisplayName"%></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    then in the code behind

    protected void Page_Load(object sender, EventArgs e)
    {
        var visibleTables = from t in Global.DefaultModel.VisibleTables.ToList()
                            select new
                                {
                                    DisplayName = t.DisplayName,
                                    ListActionPath = t.ListActionPath,
                                    Description = t.GetDescription()
                                };
    
    
        if (visibleTables.Count() == 0)
        {
            throw new InvalidOperationException("There are no accessible tables...");
        }
        Menu1.DataSource = visibleTables;
        Menu1.DataBind();
    }
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 7, 2012 1:26 PM
  • User-647007878 posted

    Thank you very much!

    I have just changed a bit of my code and voila!

    Sorry for Russian.

            // Вывод в меню основных таблиц, не скрытых по умолчанию
            private void GetMainTable()
            {
                var tablesInDefaultPage = (from
                                              Tables in MetaModel.Default.VisibleTables.ToList()
                                           where
                                               (!Tables.Attributes.OfType<HideTableInDefaultAttribute>().DefaultIfEmpty(HideTableInDefaultAttribute.Default).First().Hide
                                               & !Tables.DisplayName.StartsWith("Справочник", StringComparison.OrdinalIgnoreCase)
                                               & !Tables.DisplayName.StartsWith("Реестр", StringComparison.OrdinalIgnoreCase))
                                           orderby Tables.DisplayName
                                           select new
                                           {
                                               DisplayName = Tables.DisplayName,
                                               ListActionPath = Tables.ListActionPath,
                                               Description = iSite.Classes.MetaTableExtensions.GetDescription(Tables)
                                           }).ToList();
    
                if (tablesInDefaultPage.Count == 0)
                {
                    throw new InvalidOperationException("Нет ни одной доступной таблицы. Убедитесь, что по крайней мере одна модель данных зарегистрирована в Global.asax, технология scaffolding включена или реализованы настраиваемые страницы.");
                }
    
                this.tblMenuMainTables.DataSource = tablesInDefaultPage;
                this.tblMenuMainTables.DataBind();
            }
    

    Tuesday, February 7, 2012 11:43 PM
  • User-330204900 posted

    Hi konstantin.konstantinov, no problem with the Russin (other than I don't read Russian Laughing or speak it I only just manage English my only language) I'm glad you are working.

    Wednesday, February 8, 2012 5:51 AM