View-ForumsGroupView.ascx 读解

时间:2022-04-26
本文章向大家介绍View-ForumsGroupView.ascx 读解,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

为了修改首页的框架,一路跟踪到了View-ForumsGroupView.ascx这个文件,其实他就是一个页面的模版,微软在这里并没有弄了太多花絮,所以阅读起来很方便。

<%@ Control Language="C#" %> 
<%@ Register TagPrefix="Forums" Namespace="AspNetForums.Controls" Assembly="AspNetForums.Controls" %> 
<%@ Import Namespace="AspNetForums" %> 
<%@ Import Namespace="AspNetForums.Controls" %> 
<%@ Import Namespace="AspNetForums.Components" %>

导入了一些名称空间,并且声明了一个控件。

<Forums:Ads Zone="Inline" runat="server" />

注释上显示是广告,我个人理解为登入框上面的banner。

<%    if ( Users.GetUser().IsAnonymous ) { %> 
<table width="100%" cellspacing="0" cellpadding="5" border="0"> 
    <tr> 
        <td> 
            <!-- ForumGroupView.Header.End --> 
            <Forums:Login SkinFilename="Skin-LoginSmall.ascx" runat="server" ID="Login1" /> 
            <!-- ForumGroupView.MainCentent.Start --> 
        </td> 
    </tr> 
</table> 
<%    }    %>

匿名用户显示的表格,感觉和动网的有些类似。

<table width="100%" cellpadding="5" cellspacing="0"> 
    <tr> 
        <td valign="bottom" colspan="2"> 
            <table width="100%" cellpadding="0" cellspacing="0"> 
                <tr> 
                    <td class="txt4" align="left" nowrap> 
                        <Forums:DisplayUserWelcome runat="server" /> 
                    </td> 
                    <td class="txt4" align="right" valign="bottom" nowrap> 
                        <%    if ( !Users.GetUser().IsAnonymous ) { %> 
                        <a class="lnk3" href="<%=Globals.GetSiteUrls().MyFavorites%>"> 
                            <%=ResourceManager.GetString("MyFavorites_Description")%> 
                        </a> 
                        <br /> 
                        <!--<Forums:MarkAllRead runat="server" ID="Markallread1"/>--> 
                        <% } %> 
                        <Forums:ForumAnchor class="lnk3" AnchorType="PostsActive" runat="server" /><br /> 
                        <Forums:ForumAnchor class="lnk3" AnchorType="PostsUnanswered" runat="server" /><br /> 
                    </td> 
                </tr> 
                <tr> 
                    <td align="left"> 
                        <Forums:BreadCrumb ShowHome="true" runat="server" ID="Breadcrumb1" /> 
                    </td> 
                    <td align="right" class="txt4"> 
                        <Forums:SearchRedirect ID="SearchRedirect" runat="server" /> 
                    </td> 
                </tr> 
            </table> 
        </td> 
    </tr> 
</table>

这个就是登入以后所显示的表格。

下面就是论坛组的显示了,我们公司就是要我修改这里,所以准备一点一点分析。

<asp:Repeater EnableViewState="false" runat="server" id="forumGroupRepeater">

定义了一个Repeater控件,用来显示整个论坛组框架。

<HeaderTemplate> 
                    <!-- ********* Repeater.Header.Start ************* //--> 
                    <table width="100%" class="tableBorder" cellpadding="4" cellspacing="1"> 
                        <tr> 
                            <td colspan="2" class="column" align="center" width="*"><% = ResourceManager.GetString("ForumGroupView_Inline1") %></td> 
                            <td class="column" align="center" width="177" nowrap><%= ResourceManager.GetString("ForumGroupView_Inline4") %></td> 
                            <td class="column" align="center" width="65" nowrap><%= ResourceManager.GetString("ForumGroupView_Inline2") %></td> 
                            <td class="column" align="center" width="65" nowrap><%= ResourceManager.GetString("ForumGroupView_Inline3") %></td> 
                        </tr> 
                    </table> 
                    <!-- ********* Repeater.HeaderTemplate.End ************* //--> 
                </HeaderTemplate>

定义了头模板,ResourceManager.GetString(),让我看了很长时间,个人以为是整理了一下字符串,然后又从配置里面把数据读出,从Language目录里的Resources.xml读出数据。

<td class="fh1" colspan="5" valign="bottom"> 
   <asp:ImageButton ID="ExpandCollapse" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ForumGroupID") %>' ImageUrl='<%# Formatter.ExplandCollapseIcon( (ForumGroup) Container.DataItem ) %>' ToolTip='<%# ResourceManager.GetString("ForumGroupView_ExpandCollapse")%>' Runat="server"/> &nbsp;<a href="<%# Globals.GetSiteUrls().ForumGroup ( (int) DataBinder.Eval(Container.DataItem, "ForumGroupID")) %>"><%# DataBinder.Eval(Container.DataItem, "Name") %></a> 
 </td>

这个表格显示了一个图片和论坛组的名字。

<Forums:ForumRepeater ForumGroupID='<%# DataBinder.Eval(Container.DataItem, "ForumGroupID") %>' HideForums='<%# DataBinder.Eval(Container.DataItem, "HideForums") %>' runat="server">

这是一个自定义的Repeater控件,具体代码还没研究过。

<td class="f1" width="20"> 
<%# Formatter.StatusIcon( (Forum)Container.DataItem ) %> 
</td>

这个是显示版面是否有信息的那个图片。

<Forums:ForumLogo runat="server" Forum='<%# (Forum) Container.DataItem %>' />

这个是版面的logo,如果有就显示,没有就不显示,都在ForumsRepeater控件里都有了。

<b><a href="<%# Globals.GetSiteUrls().Forum( ((Forum) Container.DataItem).ForumID ) %>"> 
                                                    <%# DataBinder.Eval(Container.DataItem, "Name") %> 
                                                </a></b> 
                                            <%# Formatter.FormatUsersViewingForum( (Forum) Container.DataItem ) %> 
                                            <br />

这个很容易理解,就是版面名字的显示,<%# Formatter.FormatUsersViewingForum( (Forum) Container.DataItem ) %> 是显示版面现在的在线人数,很多余的东西,缓存太久了,根本不能及时显示。

<span class="txt5"></span><%# DataBinder.Eval(Container.DataItem, "Description") %><%# Formatter.FormatSubForum( (Forum) Container.DataItem ) %></span> 
<br /> 
<forums:ForumModerators runat="server" ForumID='<%# ((Forum)Container.DataItem).ForumID %>'/>

版面的简介和版主显示

<td class="fh3" align="center" width="175"> 
    <%# Formatter.FormatLastPost( (Forum) Container.DataItem, (bool) true ) %> 
</td> 
<td class="fh3" align="center" width="64"> 
    <%# Formatter.FormatNumber( ((Forum) Container.DataItem).TotalThreads ) %> 
</td> 
<td class="fh3" align="center" width="65"> 
    <%# Formatter.FormatNumber( ((Forum) Container.DataItem).TotalPosts ) %> 
</td>

这三个分别显示:最后帖子,主题数,帖子数的。

好了,后面都是一些闭合语句了。

分析完毕,现在修改起来也简单了,以后研究的时候会继续贴上来的,嘿嘿

版面的简介和版主显示 这三个分别显示:最后帖子,主题数,帖子数的。好了,后面都是一些闭合语句了。分析完毕,现在修改起来也简单了,以后研究的时候会继续贴上来的,嘿嘿