示例#1
0
        private void BindToDataItem(object dataItem)
        {
            dataItem = Misc.GetRealDataItem(dataItem);
            Debug.Assert(dataItem != null, "DataItem is null");
            // Try to get the MetaTable from the type and if we can't find it then ---- up.
            MetaTable table = Misc.GetTableFromTypeHierarchy(dataItem.GetType());

            if (table == null)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        DynamicDataResources.MetaModel_EntityTypeDoesNotBelongToModel,
                                                        dataItem.GetType().FullName));
            }

            string action = GetActionOrDefaultTo(PageAction.Details);

            NavigateUrl = table.GetActionPath(action, GetRouteValues(table, dataItem));

            if (String.IsNullOrEmpty(Text))
            {
                if (!String.IsNullOrEmpty(DataField))
                {
                    Text = DataBinder.GetPropertyValue(dataItem, DataField).ToString();
                }
                else
                {
                    Text = table.GetDisplayString(dataItem);
                }
            }
        }