none
err : creating custom dynamic tabs within each page control reportviewerwebpart RRS feed

  • Discussion générale

  • Hello,

    I created a custom dynamic tabs on visual studio, using visualwebpart.

    Foreach tab i am creating and adding dynamicaly control reportviewerwebpart :

    I have any error but a don't get render of my reports.

    Thank's for you help:

    here my code :

      [ToolboxItemAttribute(false)]
        [CSSDependecy("STYLES/jQuery-Tab/jquery-ui-1.8.custom.css", Priority = 0)]
        [ScriptDependecy("STYLES/jQuery-Tab/jquery-1.4.1.min.js", Priority = 2)]
        [ScriptDependecy("STYLES/jQuery-Tab/jquery-ui-1.8.custom.min.js", Priority = 20)]
        public class TabWebPart : WebPart
        {
            // Visual Studio might automatically update this path when you change the Visual Web Part project item.
            private const string _ascxPath = @"~/_CONTROLTEMPLATES/dtf.Report.Viewer/TabWebPart/TabWebPartUserControl.ascx";
            const string resourceBasePath = "/_layouts/";     


            protected override void CreateChildControls()
            {           
                Control control = Page.LoadControl(_ascxPath);
                TabWebPartUserControl tabUserControl = control as TabWebPartUserControl;
                if (tabUserControl != null)
                {
                    tabUserControl.tab = this;
                }
                try
                {
                    this.Controls.Add(control);
                }
                catch
                {
                }
            }

            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);

                IEnumerable<CSSDependecyAttribute> cssDependencies = this.GetType().GetCustomAttributes(typeof(CSSDependecyAttribute), true).OfType<CSSDependecyAttribute>().OrderBy(attr => attr.Priority);
                foreach (CSSDependecyAttribute attribute in cssDependencies)
                    if (Page.Items[attribute.Path] == null && Page.Header != null)
                    {
                        Page.Items[attribute.Path] = new Object();
                        Page.Header.Controls.Add(new Literal { Text = string.Format("<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}\" />", Path.Combine(resourceBasePath, attribute.Path)) });
                    }
                IEnumerable<ScriptDependecyAttribute> scriptDependencies = this.GetType().GetCustomAttributes(typeof(ScriptDependecyAttribute), true).OfType<ScriptDependecyAttribute>().OrderBy(attr => attr.Priority);
                foreach (ScriptDependecyAttribute attribute in scriptDependencies)
                    if (Page.Items[attribute.Path] == null && Page.Header != null)
                    {
                        Page.Items[attribute.Path] = new Object();
                        Page.Header.Controls.Add(new Literal { Text = string.Format("<script src=\"{0}\" type=\"text/javascript\"></script>", Path.Combine(resourceBasePath, attribute.Path)) });
                    }
            }
        }
    }

    --------------------------

    <link type="text/css" rel="stylesheet" href="{0}" />

    <script type="text/javascript">
        $(function () {   
            $("#tabs<%= this.ClientID%>").tabs();
        });
    </script>

     

    <div id="tabs<%= this.ClientID%>">

          <ul>
            <asp:Repeater runat="server" ID="TabRepeater" >
                <ItemTemplate>               
                     <li>
                        <a href="#tabs<%# this.ClientID%>-<%# Container.ItemIndex + 1 %>"><%# Container.DataItem%></a>
                    </li>
                </ItemTemplate>
            </asp:Repeater>
          </ul>

        <asp:Repeater runat="server" ID="TabContainerRepeater"  onitemdatabound="TabContainerRepeater_ItemDataBound">
            <ItemTemplate>           
                  <div id="tabs<%# this.ClientID%>-<%# Container.ItemIndex + 1 %>" class="ui-tabs-hide">
                    <asp:Panel runat="server" ID="TabContainer" Visible="true">
                           
                    </asp:Panel>
                  </div>
            </ItemTemplate>
        </asp:Repeater>

    </div>

    -----------------------

     public partial class TabWebPartUserControl : UserControl
        {
            public TabWebPart tab { get; set; }
            public List<string> tabList = new List<string>();
            string tabsConfigurationString;
            TextReader textReader = null;
            XDocument xDocument = null;
            List<DtfProfile.UniverseType> _domaines = new List<DtfProfile.UniverseType>();
            string _hierarchy = string.Empty;
            string _profileType = string.Empty;
            int _idDealer = 0;

            string _report = string.Empty;


            protected void Page_Load(object sender, EventArgs e)
            {
                // Create file xml
                DtfProfile profile = new DtfProfile();
                string membership = "i:0#.f|membersp_authentification|";
                profile.Initialize(SPContext.Current.Web.CurrentUser.LoginName.Replace(membership, ""), true);
                _domaines = profile.Domaine;
                _hierarchy = profile.Hierarchy.ToString();
                _idDealer = profile.SynergyCode;
                _profileType = profile.Type.ToString();

                string test = string.Empty;

                XElement root = new XElement("tabs");
                foreach (var _domaine in _domaines)
                {

                    var xml = new XElement("tab",
                               new XAttribute("name", _domaine.ToString()),

                               new XElement("webPart",
                               new XAttribute("title", _domaine.ToString())));
                    root.Add(xml);
                }
                tabsConfigurationString = root.ToString();

                // lecture du fichier xml
                textReader = new StringReader(tabsConfigurationString);
                xDocument = XDocument.Load(textReader);

                var tabNames = from t in xDocument.Descendants("tab")
                               select (string)t.Attribute("name");

                foreach (string tabName in tabNames)
                {
                    tabList.Add(tabName);
                }

                // For tab titles
                this.TabRepeater.DataSource = tabList;
                this.TabRepeater.DataBind();

                // For tab contents
                this.TabContainerRepeater.DataSource = tabList;
                this.TabContainerRepeater.DataBind();
            }


            protected ReportViewerWebPart GetWebPart(string _title)
            {
                // create CAML query
                SPQuery _Query = new SPQuery();
                string requete = string.Format(@"<Where>
                                                <And>
                                                    <Eq><FieldRef Name='Hierarchy' /><Value Type='Choice'>{0}</Value></Eq>
                                                <And>
                                                    <Eq><FieldRef Name='Domaine' /><Value Type='Choice'>{1}</Value></Eq>
                                                <And>
                                                <Eq><FieldRef Name='ProfileType' /><Value Type='Choice'>{2}</Value></Eq>
                                                <Eq><FieldRef Name='DocumentType' /><Value Type='Choice'>Dashboard</Value></Eq>
                                                </And></And></And>
                                                </Where>", _hierarchy, _title, _profileType);

                _Query.Query = requete;
                _Query.ViewAttributes = "Scope='Recursive'";

                SPDocumentLibrary _reportLibrary = (SPDocumentLibrary)SPContext.Current.Web.Lists["ReportLibrary"];

                SPListItemCollection col = _reportLibrary.GetItems(_Query);
                if (col.Count > 0)
                {
                    SPListItem item = col[0];
                    _report = item.Url;
                }

              

                ReportViewerWebPart wp = new ReportViewerWebPart();
                wp.ReportPath = SPContext.Current.Web.Url + "/" + _report;

                //wp.Height = "2000px";
                return wp;
            }


            protected void TabContainerRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                Panel panel = (Panel)e.Item.FindControl("TabContainer");

                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    if (panel != null)
                    {
                        try
                        {
                            var webPartTitles = from t in xDocument.Descendants("webPart")
                                                where (string)t.Parent.Attribute("name") == (string)e.Item.DataItem
                                                select (string)t.Attribute("title");

                            int i = webPartTitles.Count();
                            foreach (string _wpTitle in webPartTitles)
                            {

                                ReportViewerWebPart wp = GetWebPart(_wpTitle);
                                panel.Controls.Add(wp);

                                break;
                            }
                        }

                        catch (Exception ex)
                        {
                            // For debugging use only.
                            Label label = new Label();
                            label.Text = "Please check your XML configuration for error. " + Environment.NewLine + ex.Message;
                            panel.Controls.Add(label);
                        }
                    }
                }
            }
        }
    }

    • Déplacé Gokan OzcifciMVP mardi 18 décembre 2012 13:00 Question Développement (Origine :Sharepoint 2013,2010, 2007 et versions antérieures pour les professionnels IT)
    mardi 18 décembre 2012 07:47

Toutes les réponses

  • Hello,

    I am trying to developpe dynamic tab in sharepoint using visual webpart.

    I am adding dynamicaly a control Report ViewerWebpart, and i have any render of it.

    Please i need help..Thank's

    Here my code :

     public partial class TabWebPartUserControl : UserControl
        {
            public TabWebPart tab { get; set; }
            public List<string> tabList = new List<string>();
            string tabsConfigurationString;
            TextReader textReader = null;
            XDocument xDocument = null;
            List<DtfProfile.UniverseType> _domaines = new List<DtfProfile.UniverseType>();
            string _hierarchy = string.Empty;
            string _profileType = string.Empty;
            int _idDealer = 0;

            string _report = string.Empty;


            protected void Page_Load(object sender, EventArgs e)
            {
                // Create file xml
                DtfProfile profile = new DtfProfile();
                string membership = "i:0#.f|membersp_authentification|";
                profile.Initialize(SPContext.Current.Web.CurrentUser.LoginName.Replace(membership, ""), true);
                _domaines = profile.Domaine;
                _hierarchy = profile.Hierarchy.ToString();
                _idDealer = profile.SynergyCode;
                _profileType = profile.Type.ToString();

                string test = string.Empty;

                XElement root = new XElement("tabs");
                foreach (var _domaine in _domaines)
                {

                    var xml = new XElement("tab",
                               new XAttribute("name", _domaine.ToString()),

                               new XElement("webPart",
                               new XAttribute("title", _domaine.ToString())));
                    root.Add(xml);
                }
                tabsConfigurationString = root.ToString();

                // lecture du fichier xml
                textReader = new StringReader(tabsConfigurationString);
                xDocument = XDocument.Load(textReader);

                var tabNames = from t in xDocument.Descendants("tab")
                               select (string)t.Attribute("name");

                foreach (string tabName in tabNames)
                {
                    tabList.Add(tabName);
                }

                // For tab titles
                this.TabRepeater.DataSource = tabList;
                this.TabRepeater.DataBind();

                // For tab contents
                this.TabContainerRepeater.DataSource = tabList;
                this.TabContainerRepeater.DataBind();
            }


            protected ReportViewerWebPart GetWebPart(string _title)
            {
                // create CAML query
                SPQuery _Query = new SPQuery();
                string requete = string.Format(@"<Where>
                                                <And>
                                                    <Eq><FieldRef Name='Hierarchy' /><Value Type='Choice'>{0}</Value></Eq>
                                                <And>
                                                    <Eq><FieldRef Name='Domaine' /><Value Type='Choice'>{1}</Value></Eq>
                                                <And>
                                                <Eq><FieldRef Name='ProfileType' /><Value Type='Choice'>{2}</Value></Eq>
                                                <Eq><FieldRef Name='DocumentType' /><Value Type='Choice'>Dashboard</Value></Eq>
                                                </And></And></And>
                                                </Where>", _hierarchy, _title, _profileType);

                _Query.Query = requete;
                _Query.ViewAttributes = "Scope='Recursive'";

                SPDocumentLibrary _reportLibrary = (SPDocumentLibrary)SPContext.Current.Web.Lists["ReportLibrary"];

                SPListItemCollection col = _reportLibrary.GetItems(_Query);
                if (col.Count > 0)
                {
                    SPListItem item = col[0];
                    _report = item.Url;
                }

              

                ReportViewerWebPart wp = new ReportViewerWebPart();
                wp.ReportPath = SPContext.Current.Web.Url + "/" + _report;

                //wp.Height = "2000px";
                return wp;
            }


            protected void TabContainerRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                Panel panel = (Panel)e.Item.FindControl("TabContainer");

                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    if (panel != null)
                    {
                        try
                        {
                            var webPartTitles = from t in xDocument.Descendants("webPart")
                                                where (string)t.Parent.Attribute("name") == (string)e.Item.DataItem
                                                select (string)t.Attribute("title");

                            int i = webPartTitles.Count();
                            foreach (string _wpTitle in webPartTitles)
                            {

                                ReportViewerWebPart wp = GetWebPart(_wpTitle);
                                panel.Controls.Add(wp);

                                break;
                            }
                        }

                        catch (Exception ex)
                        {
                            // For debugging use only.
                            Label label = new Label();
                            label.Text = "Please check your XML configuration for error. " + Environment.NewLine + ex.Message;
                            panel.Controls.Add(label);
                        }
                    }
                }
            }
        }
    }

    ---------------------

    <link type="text/css" rel="stylesheet" href="{0}" />

    <script type="text/javascript">
        $(function () {   
            $("#tabs<%= this.ClientID%>").tabs();
        });
    </script>

    <div id="tabs<%= this.ClientID%>">

          <ul>
            <asp:Repeater runat="server" ID="TabRepeater" >
                <ItemTemplate>               
                     <li>
                        <a href="#tabs<%# this.ClientID%>-<%# Container.ItemIndex + 1 %>"><%# Container.DataItem%></a>
                    </li>
                </ItemTemplate>
            </asp:Repeater>
          </ul>

        <asp:Repeater runat="server" ID="TabContainerRepeater"  onitemdatabound="TabContainerRepeater_ItemDataBound">
            <ItemTemplate>           
                  <div id="tabs<%# this.ClientID%>-<%# Container.ItemIndex + 1 %>" class="ui-tabs-hide">
                    <asp:Panel runat="server" ID="TabContainer" Visible="true">
                           
                    </asp:Panel>
                  </div>
            </ItemTemplate>
        </asp:Repeater>

    </div>

    ----------------------------------


        [ToolboxItemAttribute(false)]
        [CSSDependecy("STYLES/jQuery-Tab/jquery-ui-1.8.custom.css", Priority = 0)]
        [ScriptDependecy("STYLES/jQuery-Tab/jquery-1.4.1.min.js", Priority = 2)]
        [ScriptDependecy("STYLES/jQuery-Tab/jquery-ui-1.8.custom.min.js", Priority = 20)]
        public class TabWebPart : WebPart
        {
            // Visual Studio might automatically update this path when you change the Visual Web Part project item.
            private const string _ascxPath = @"~/_CONTROLTEMPLATES/dtf.Report.Viewer/TabWebPart/TabWebPartUserControl.ascx";
            const string resourceBasePath = "/_layouts/";     


            protected override void CreateChildControls()
            {           
                Control control = Page.LoadControl(_ascxPath);
                TabWebPartUserControl tabUserControl = control as TabWebPartUserControl;
                if (tabUserControl != null)
                {
                    tabUserControl.tab = this;
                }
                try
                {
                    this.Controls.Add(control);
                }
                catch
                {
                }
            }

            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);

                IEnumerable<CSSDependecyAttribute> cssDependencies = this.GetType().GetCustomAttributes(typeof(CSSDependecyAttribute), true).OfType<CSSDependecyAttribute>().OrderBy(attr => attr.Priority);
                foreach (CSSDependecyAttribute attribute in cssDependencies)
                    if (Page.Items[attribute.Path] == null && Page.Header != null)
                    {
                        Page.Items[attribute.Path] = new Object();
                        Page.Header.Controls.Add(new Literal { Text = string.Format("<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}\" />", Path.Combine(resourceBasePath, attribute.Path)) });
                    }
                IEnumerable<ScriptDependecyAttribute> scriptDependencies = this.GetType().GetCustomAttributes(typeof(ScriptDependecyAttribute), true).OfType<ScriptDependecyAttribute>().OrderBy(attr => attr.Priority);
                foreach (ScriptDependecyAttribute attribute in scriptDependencies)
                    if (Page.Items[attribute.Path] == null && Page.Header != null)
                    {
                        Page.Items[attribute.Path] = new Object();
                        Page.Header.Controls.Add(new Literal { Text = string.Format("<script src=\"{0}\" type=\"text/javascript\"></script>", Path.Combine(resourceBasePath, attribute.Path)) });
                    }
            }
        }
    }

    mardi 18 décembre 2012 07:36
  • Hello,

    2 things wrong here. The first one is that you are in the FRENCH forum of Technet and the other one is that your question is concerning development problem and you are in the IT Pro forum...

    Bad day, I know ;-)

    Can you please ask your question in french and in the good forum? Otherwise you have access to the english forums here : http://social.technet.microsoft.com/Forums/en-US/category/sharepoint/

    Thank you ;-)


    Pascal P
    http://sharepoint-afterwork.fr
    Twitter: @PascalPoeck
    Facebook : https://www.facebook.com/SharePointAfterWork

    mardi 18 décembre 2012 10:10