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

📄 comments.cs

📁 ASP开发网站的 关于网站的设计和说明 还有SQL的程序 数据库
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    ListItem item = dropCommentView.Items.FindByValue(commentView.ToString());
                    if (item != null)
                        item.Selected = true;
                }
                else
                    commentView = Int32.Parse(dropCommentView.SelectedItem.Value);

                // Remember view in Session State
                Context.Session["CommentView"] = commentView;
 
                InitializeHandlers();
                InitializeTemplates();
                BindComments();
            }
         }


        //*********************************************************************
        //
        // InitializeHandlers Method
        //
        // Assigns ItemDataBound handlers to the Repeater depending on
        // the view of the comments (threaded, nested, and so on).
        //
        //*********************************************************************

        private void InitializeHandlers() {
            // Display Comments
            switch (commentView) {
                case 1:
                    ctlCommentList.ItemDataBound += new ContentListItemEventHandler(Repeater_ItemDataBoundNested);
                    break;
                case 2:
                    ctlCommentList.ItemDataBound += new ContentListItemEventHandler(Repeater_ItemDataBoundThreaded);
                    break;
                case 3:
                    ctlCommentList.ItemDataBound += new ContentListItemEventHandler(Repeater_ItemDataBoundNested);
                    break;
                default:
                    ctlCommentList.ItemDataBound += new ContentListItemEventHandler(Repeater_ItemDataBoundFlat);
                    break;
            }
        }


        //*********************************************************************
        //
        // InitializeTemplates Method
        //
        // Assigns templates to the Repeater depending on
        // the view of the comments (threaded, nested, and so on).
        //
        //*********************************************************************

        private void InitializeTemplates() {

            // Display Comments
            switch (commentView) {
                case 1:
                    ctlCommentList.HeaderTemplate = LoadTemplate(_headerTemplate + "-Nested.ascx");
                    ctlCommentList.ItemTemplate = LoadTemplate(_itemTemplate + "-Nested.ascx");
                    ctlCommentList.SeparatorTemplate = LoadTemplate(_separatorTemplate + "-Nested.ascx");
                    ctlCommentList.FooterTemplate = LoadTemplate(_footerTemplate + "-Nested.ascx");
                    break;
                case 2:
                    ctlCommentList.HeaderTemplate = LoadTemplate(_headerTemplate + "-Threaded.ascx");
                    ctlCommentList.ItemTemplate = LoadTemplate(_itemTemplate + "-Threaded.ascx");
                    ctlCommentList.SeparatorTemplate = LoadTemplate(_separatorTemplate + "-Threaded.ascx");
                    ctlCommentList.FooterTemplate = LoadTemplate(_footerTemplate + "-Threaded.ascx");
                    break;
                case 3:
                    ctlCommentList.HeaderTemplate = LoadTemplate(_headerTemplate + "-Embedded.ascx");
                    ctlCommentList.ItemTemplate = LoadTemplate(_itemTemplate + "-Embedded.ascx");
                    ctlCommentList.SeparatorTemplate = LoadTemplate(_separatorTemplate + "-Embedded.ascx");
                    ctlCommentList.FooterTemplate = LoadTemplate(_footerTemplate + "-Embedded.ascx");
                    break;
                default:
                    ctlCommentList.HeaderTemplate = LoadTemplate(_headerTemplate + "-Flat.ascx");
                    ctlCommentList.ItemTemplate = LoadTemplate(_itemTemplate + "-Flat.ascx");
                    ctlCommentList.SeparatorTemplate = LoadTemplate(_separatorTemplate + "-Flat.ascx");
                    ctlCommentList.FooterTemplate = LoadTemplate(_footerTemplate + "-Flat.ascx");
                    break;
            }
        }


        //*********************************************************************
        //
        // BindComments Method
        //
        // Retrieves and displays the comments.
        //
        //*********************************************************************

        private void BindComments() {    
             // Get Comments
            colComments = CommentUtility.GetComments(objUserInfo.Username, ContentPageID, Int32.Parse(dropOrderBy.SelectedItem.Value));

            if (colComments.Count > 0) {
                // Show Comments Panel
                pnlComments.Visible = true;
                if (Int32.Parse(dropCommentView.SelectedItem.Value) == 0)
                    ctlCommentList.DataSource = colComments;
                else
                    ctlCommentList.DataSource = colComments.GetChildren(ContentPageID);
                    
                this.DataBind();

            }
            else
                pnlComments.Visible = false;
        }


        //*********************************************************************
        //
        // Repeater_ItemDataBoundFlat Method
        //
        // Displays comments using the flat view.
        //
        //*********************************************************************

        private void Repeater_ItemDataBoundFlat(Object s, ContentListItemEventArgs e) {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
            }
        }



        //*********************************************************************
        //
        // Repeater_ItemDataBoundThreaded Method
        //
        // Displays comments using the threaded view.
        //
        //*********************************************************************

        private void Repeater_ItemDataBoundThreaded(Object s, ContentListItemEventArgs e) {
            ContentList nestedComments;
            CommentCollection colNestedComments;
            int commentID;

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
                
                // Display Nested Comments
                commentID = ((CommentInfo)e.Item.DataItem).ContentPageID;
                colNestedComments = colComments.GetChildren(commentID);
                                
                // Bind to Nested Repeater
                if (colNestedComments.Count>0) {
                    nestedComments = (ContentList)e.Item.Controls[0].FindControl("ThreadedComments");
                    nestedComments.ItemTemplate = LoadTemplate("Comments_DisplayComments-ItemTemplate-Threaded.ascx");
                    nestedComments.ItemDataBound += new ContentListItemEventHandler(Repeater_ItemDataBoundThreaded);
                    nestedComments.SeparatorTemplate = LoadTemplate("Comments_DisplayComments-SeparatorTemplate-Threaded.ascx");
                    nestedComments.DataSource = colNestedComments;
                    nestedComments.DataBind();
                }
            }
        }


        //*********************************************************************
        //
        // Repeater_ItemDataBoundNested Method
        //
        // Displays comments using the nested view.
        //
        //*********************************************************************
        private void Repeater_ItemDataBoundNested(Object s, ContentListItemEventArgs e) {
            ContentList nestedComments;
            CommentCollection colNestedComments;
            int commentID;


            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
               
                // Display Nested Comments
                commentID = ((CommentInfo)e.Item.DataItem).ContentPageID;
                colNestedComments = colComments.GetChildren(commentID);
                                
                // Bind to Nested Repeater
                if (colNestedComments.Count>0) {
                    nestedComments = (ContentList)e.Item.Controls[0].FindControl("NestedComments");
                    nestedComments.ItemTemplate = LoadTemplate(_itemTemplate + "-Nested.ascx");
                    nestedComments.ItemDataBound += new ContentListItemEventHandler(Repeater_ItemDataBoundNested);
                    nestedComments.SeparatorTemplate = LoadTemplate("Comments_DisplayComments-SeparatorTemplate-Nested.ascx");
                    nestedComments.DataSource = colNestedComments;
                    nestedComments.DataBind();
                }
            }
        }
    }
}

⌨️ 快捷键说明

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