Ejemplo n.º 1
0
    public void BindData()
    {
        if (WebpartId != "")
        {
            // Get page info
            pi = CMSWebPartPropertiesPage.GetPageInfo(AliasPath, PageTemplateId, CultureCode);
            if (pi == null)
            {
                Visible = false;
                return;
            }

            // Get page template info
            pti = pi.UsedPageTemplateInfo;
            if (pti != null)
            {
                // Get web part instance
                webPart = pti.GetWebPart(InstanceGUID, WebpartId);
                if (webPart == null)
                {
                    CMSPage.EditedObject = null;
                    return;
                }

                // Get the web part info
                WebPartInfo wpi = WebPartInfoProvider.GetBaseWebPart(webPart.WebPartType);
                if (wpi == null)
                {
                    return;
                }

                // Get webpart properties (XML)
                string   wpProperties = wpi.WebPartProperties;
                FormInfo fi           = PortalFormHelper.GetWebPartFormInfo(wpi.WebPartName + FormHelper.CORE, wpi.WebPartProperties, null, null, false);

                // Get datarow with required columns
                DataRow dr = fi.GetDataRow();

                // Bind drop down list
                if (!RequestHelper.IsPostBack())
                {
                    DataTable dropTable = new DataTable();
                    dropTable.Columns.Add("name");

                    foreach (DataColumn column in dr.Table.Columns)
                    {
                        dropTable.Rows.Add(column.ColumnName);
                    }

                    dropTable.DefaultView.Sort = "name";
                    drpProperty.DataTextField  = "name";
                    drpProperty.DataValueField = "name";
                    drpProperty.DataSource     = dropTable.DefaultView;
                    drpProperty.DataBind();
                }

                // Bind grid view
                DataTable table = new DataTable();
                table.Columns.Add("LocalProperty");
                table.Columns.Add("SourceProperty");
                bindings = webPart.Bindings;

                foreach (DataColumn column in dr.Table.Columns)
                {
                    string propertyName = column.ColumnName.ToLowerCSafe();
                    if (bindings.ContainsKey(propertyName))
                    {
                        WebPartBindingInfo bi = (WebPartBindingInfo)bindings[propertyName];
                        table.Rows.Add(column.ColumnName, bi.SourceWebPart + "." + bi.SourceProperty);
                    }
                }

                gvBinding.DataSource = table;
                gvBinding.DataBind();
            }
        }
    }