⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postlist.cs

📁 微软的.NET论坛的源代码(COOL!!!)
💻 CS
📖 第 1 页 / 共 2 页
字号:
            }

            // Moderator?
            if (user.IsModerator) {
                tr = new TableRow();
                td = new TableCell();
                image = new Image();
                image.ImageUrl = Globals.ApplicationVRoot + "/skins/" + siteStyle + "/images/users_moderator.gif";
                image.AlternateText = "Forum Moderator";
                td.Controls.Add(image);
                tr.Controls.Add(td);
                table.Controls.Add(tr);
            }

            // Add a little whitespace
            tr = new TableRow();
            td = new TableCell();
            td.Text = " ";
            tr.Controls.Add(td);
            table.Controls.Add(tr);

            // Add table to placeholder
            userInfo.Controls.Add(table);
        }

        // *********************************************************************
        //  RenderHeaderTemplate
        //
        /// <summary>
        /// This function renders the header template
        /// </summary>
        /// 
        // ********************************************************************/
        private Control RenderHeaderTemplate() {
            PostCollection posts;
            Table table = new Table();
            TableRow tr;
            TableHeaderCell th;

            // Get details about this post and ensure
            // we get the root post
            posts = (PostCollection) DataSource;

            // Titles row
            tr = new TableRow();

            // Authors
            th = new TableHeaderCell();
            th.Height = Unit.Pixel(25);
            th.CssClass = "tableHeaderText";
            th.Width = 100;
            
            th.HorizontalAlign = HorizontalAlign.Left;
            th.Text = "&nbsp;Author";
            tr.Controls.Add(th);

            // Messages
            th = new TableHeaderCell();
            th.CssClass = "tableHeaderText";
            th.Width = Unit.Percentage(85);
            th.HorizontalAlign = HorizontalAlign.Left;
            th.Text = "&nbsp;Thread: " + ((Post)posts[0]).Subject;
            
            tr.Controls.Add(th);


            // Add header row to table
            table.Controls.Add(tr);

            return table;
        }

        // *********************************************************************
        //  RenderItemTemplate
        //
        /// <summary>
        /// This function renders the item template for flat display
        /// </summary>
        /// 
        // ********************************************************************/
        private Control RenderItemTemplate() {
            Table table = new Table();
            TableRow tr = new TableRow();
            TableCell authorCell = new TableCell();
            TableCell postCell = new TableCell();

            // Author Cell Details
            authorCell.VerticalAlign = VerticalAlign.Top;
            authorCell.CssClass = "forumRow";
            authorCell.Wrap = false;
            authorCell.DataBinding += new System.EventHandler(HandleDataBindingForAuthorCell);

            // Post Cell Details
            postCell.VerticalAlign = VerticalAlign.Top;
            postCell.CssClass = "forumRow";
            postCell.DataBinding += new System.EventHandler(HandleDataBindingForPostCell);

            // Add controls to control tree
            tr.Controls.Add(authorCell);
            tr.Controls.Add(postCell);
            table.Controls.Add(tr);

            return table;
        }

        // *********************************************************************
        //  RenderAlternatingItemTemplate
        //
        /// <summary>
        /// This function renders the item template for flat display
        /// </summary>
        /// 
        // ********************************************************************/
        private Control RenderAlternatingItemTemplate() {
            Table table = new Table();
            TableRow tr = new TableRow();
            TableCell authorCell = new TableCell();
            TableCell postCell = new TableCell();

            // Author Cell Details
            authorCell.VerticalAlign = VerticalAlign.Top;
            authorCell.CssClass = "forumAlternate";
            authorCell.Wrap = false;
            authorCell.DataBinding += new System.EventHandler(HandleDataBindingForAuthorCell);

            // Post Cell Details
            postCell.VerticalAlign = VerticalAlign.Top;
            postCell.CssClass = "forumAlternate";
            postCell.DataBinding += new System.EventHandler(HandleDataBindingForPostCell);

            // Add controls to control tree
            tr.Controls.Add(authorCell);
            tr.Controls.Add(postCell);
            table.Controls.Add(tr);

            return table;
        }

        // *********************************************************************
        //  RenderFooterTemplate
        //
        /// <summary>
        /// This function renders the footer template
        /// </summary>
        /// 
        // ********************************************************************/
        private Control RenderFooterTemplate() {
            Table table = new Table();
            TableRow tr;
            TableCell td;

            // Titles row
            tr = new TableRow();

            // Messages
            td = new TableCell();
            td.ColumnSpan = 2;
            td.CssClass = "forumHeaderBackgroundAlternate";
            td.Height = 20;
            
            tr.Controls.Add(td);

            // Add header row to table
            table.Controls.Add(tr);

            return table;
        }

        
        // *********************************************************************
        //  BuildHeaderTemplate
        //
        /// <summary>
        /// This function is called to create the template for the header
        /// </summary>
        /// 
        // ********************************************************************/
        private void BuildHeaderTemplate(Control _ctrl) {

            System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));

            __parser.AddParsedSubObject(RenderHeaderTemplate());
            
        }

 
        // *********************************************************************
        //  BuildItemTemplate
        //
        /// <summary>
        /// This function is called to create the template for items
        /// </summary>
        /// 
        // ********************************************************************/
        private void BuildItemTemplate(Control _ctrl) {

            System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));
            __parser.AddParsedSubObject(RenderItemTemplate());
            
        }

        // *********************************************************************
        //  BuildSeparatorItemTemplate
        //
        /// <summary>
        /// This function is called to create the template for items
        /// </summary>
        /// 
        // ********************************************************************/
        private void BuildSeparatorTemplate(Control _ctrl) {
            Table table = new Table();
            TableRow tr = new TableRow();
            TableCell td = new TableCell();

            td.ColumnSpan = 2;
            td.Height = 2;
            td.CssClass = "flatViewSpacing";

            tr.Controls.Add(td);
            table.Controls.Add(tr);

            System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));
            __parser.AddParsedSubObject(table);
        }

        // *********************************************************************
        //  BuildAlternatingItemTemplate
        //
        /// <summary>
        /// This function is called to create the template for items
        /// </summary>
        /// 
        // ********************************************************************/
        private void BuildAlternatingItemTemplate(Control _ctrl) {

            System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));
            __parser.AddParsedSubObject(RenderAlternatingItemTemplate());
            
        }
        
        // *********************************************************************
        //  BuildFooterTemplate
        //
        /// <summary>
        /// This function is called to create the template for the header
        /// </summary>
        /// 
        // ********************************************************************/
        private void BuildFooterTemplate(Control _ctrl) {

            System.Web.UI.IParserAccessor __parser = ((System.Web.UI.IParserAccessor)(_ctrl));

            __parser.AddParsedSubObject(RenderFooterTemplate());
            
        }

        // *********************************************************************
        //  ApplyTemplates
        //
        /// <summary>
        /// Applies templates to control the ui generated by the control. If no
        /// template is specified a custom template is used. If a template is found
        /// in the skins directory, that template is loaded and used. If a user defined
        /// template is found, that template takes priority.
        /// </summary>
        /// 
        // ********************************************************************/
        private void ApplyTemplates() {
            string pathToHeaderTemplate;
            string pathToItemTemplate;
            string pathToAlternatingItemTemplate;
            string pathToFooterTemplate;
            string keyForHeaderTemplate;
            string keyForItemTemplate;
            string keyForAlternatingItemTemplate;
            string keyForFooterTemplate;

            // Are we using skinned template?
            if (Page != null) {

                // Set the file paths to where the templates should be found
                keyForHeaderTemplate = Globals.Skin + "/Templates/PostList-Header.ascx";
                keyForItemTemplate = Globals.Skin + "/Templates/PostList-Item.ascx";
                keyForAlternatingItemTemplate = Globals.Skin + "/Templates/PostList-AlternatingItem.ascx";
                keyForFooterTemplate = Globals.Skin + "/Templates/PostList-Footer.ascx";

                // Set the file paths to where the templates should be found
                pathToHeaderTemplate = Globals.ApplicationVRoot + "/Skins/" + keyForHeaderTemplate;
                pathToItemTemplate = Globals.ApplicationVRoot + "/skins/" + keyForItemTemplate;
                pathToAlternatingItemTemplate = Globals.ApplicationVRoot + "/skins/" + keyForAlternatingItemTemplate;
                pathToFooterTemplate = Globals.ApplicationVRoot + "/skins/" + keyForFooterTemplate;

                // Attempt to get the skinned header template
                if (HeaderTemplate == null)
                    HeaderTemplate = Globals.LoadSkinnedTemplate(pathToHeaderTemplate, keyForHeaderTemplate, Page);

                // Attempt to get the skinned item template
                if (ItemTemplate == null)
                    ItemTemplate = Globals.LoadSkinnedTemplate(pathToItemTemplate,keyForItemTemplate, Page);

                // Attempt to get the skinned alternating item template
                if (AlternatingItemTemplate == null)
                    AlternatingItemTemplate = Globals.LoadSkinnedTemplate(pathToAlternatingItemTemplate,keyForAlternatingItemTemplate, Page);

                // Attempt to get the footer template
                if (FooterTemplate == null)
                    FooterTemplate = Globals.LoadSkinnedTemplate(pathToFooterTemplate, keyForFooterTemplate, Page);
            }

            // Are any templates specified yet?
            if (ItemTemplate == null) {
                // Looks like we're using custom templates
                ExtractTemplateRows = true;

                HeaderTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildHeaderTemplate));
                ItemTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildItemTemplate));
                //TODO: BUGBUG with DATALIST? SeparatorTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildSeparatorTemplate));
                AlternatingItemTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildAlternatingItemTemplate));
                FooterTemplate = new CompiledTemplateBuilder(new BuildTemplateMethod(BuildFooterTemplate));
            }

        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -