• Repater 控件的应用(学习)



    Repater 控件的传统应用

    <asp:Repeater ID="normalArticleList" runat="server">
        
    <ItemTemplate>
            
    <div class="textbox">
                
    <div class="textbox-title">
                    
    <h4><onclick="<%# urlFormats.ArticleConent(Convert.ToInt32(Eval("ArticleID").ToString()))%>" href="#"><span runat=server visible=<%# Eval("IsTop")%>>[置顶]</span><%Eval("Title")%></a>
                    
    </h4>
                    
    <div class="textbox-label">
                        [
                        
    <%Eval("PostTime")%>
                        | 
    <%=lang["author"]%><onclick="<%# urlFormats.UserDetail(int.Parse(Eval("AuthorID").ToString()))%>" href="#"><%Eval("Author"%></a> ]</div>
                
    </div>
                
    <div class="textbox-content">
                    
    <%# GetContent(Eval("Content0").ToString(), Eval("Content1").ToString())%><%--<%# Eval("Content1"%>--%></div>
                
    <div class="textbox-bottom">
                    
    <asp:PlaceHolder ID="actionLinkPanel" runat="server">
    <href="articleManage.aspx?act=edit&id=<%# Eval("ArticleID") %>" title="<%=lang["edit"]%>">
                        
    <img src="/styles/default/images/icon_edit.gif" alt="<%=lang["edit"]%>" />
                    
    </a><href="/articleManage.aspx?act=delete&id=<%# Eval("ArticleID") %>" title="<%=lang["delete"]%>">
                        
    <img src="/styles/default/images/icon_del.gif" alt="<%=lang["delete"]%>" /></a> | 
                    
    </asp:PlaceHolder>
    <onclick="<%# urlFormats.ArticleCategoryUrl(Convert.ToInt32(Eval("categoryID").ToString()))%>" href="#"><%=lang["category"]%>:<%Eval("CategoryName")%></a> | <href="?id=<%# Eval("ArticleID") %>"><%=lang["permalink"]%></a> | <onclick="<%# urlFormats.ArticleConent(Convert.ToInt32(Eval("ArticleID").ToString()))%>" href="#commentbox" title="评论"><%=lang["comments"]%>:<%Eval("CommentCount"%></a> | <href="#"><%=lang["trackbacks"]%>:<%Eval("TrackbackCount"%></a> | <%=lang["views"]%>:<%Eval("ViewCount"%>
                
    </div>
            
    </div>
        
    </ItemTemplate>
    </asp:Repeater>


    上面的代码通过数据绑定语法,能很好的完成了工作。可这界面太烦,字段多,金黄色语法就更多,看上去很烦,但我们却无法逃避这个问题,而且有时候还需要对一些字段进行逻辑判断。

    Repater 控件的友好应用

    Literal 控件代替绑定语法,在 ItemDataBound 事件中完成数据的填充。

    前端代码:

    <asp:Repeater ID="normalArticleList" runat="server">
    <ItemTemplate>
    <div class="textbox">
        
    <div class="textbox-title">
            
    <asp:Literal ID="articleTitle" runat="server"></asp:Literal>
            
    <div class="textbox-label">
                
    <asp:Literal ID="articleLabel" runat="server"></asp:Literal>
            
    </div>
        
    </div>
        
    <div class="textbox-content">
            
    <asp:Literal ID="articleContent" runat="server"></asp:Literal>
        
    </div>
        
    <div class="textbox-bottom">
        
    <asp:Literal ID="articleBottom" runat="server"></asp:Literal>
        
    </div>
    </div>
    </ItemTemplate>
    </asp:Repeater>


    后端代码:

            void normalArticleList_ItemDataBound(object sender, RepeaterItemEventArgs e)
            
    {
                
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                
    {
                    Article item 
    = (Article)e.Item.DataItem;
                  
                    Literal title 
    = (Literal)e.Item.FindControl("articleTitle");
                    Literal articleLabel 
    = (Literal)e.Item.FindControl("articleLabel");
                    Literal articleContent 
    = (Literal)e.Item.FindControl("articleContent");
                    Literal articleBottom 
    = (Literal)e.Item.FindControl("articleBottom");
                    
                    title.Text 
    = RenderNormalTitle(item);
                    articleLabel.Text 
    = RenderNormalLabel(item);
                    articleContent.Text 
    = RenderNormalContent(item);
                    articleBottom.Text 
    = RenderNormalBottom(item);
                    
                }

            }


    这样的写法会漂亮很多,而且数据绑定是通过反射机制的,但是听说会损失性能!

    学习来源:http://www.cnblogs.com/Clingingboy/archive/2007/12/31/1021611.html
  • 相关阅读:
    java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0
    VS .sln .csproj 文件的右键编译
    任务失败,因为未找到“AxImpexe”,或未安装正确的 Microsoft Windows SDK
    对数据集“dsArea”执行查询失败。 (rsErrorExecutingCommand),Query execution failed for dataset 'dsArea'. (rsErrorExecutingCommand),Manually process the TFS data warehouse and analysis services cube
    In-Place upgrade to Team Foundation Server (TFS) 2015 from TFS 2013Team Foundation Server TFS TFS 2015 TFS upgrade TFS with Sharepoint
    VS2015开发环境的安装和配置 2016-07-03更新
    【Android】将Xamarin For VS升级为4.1.0.530版
    Win10年度更新开发必备:VS2015 正式版下载汇总
    Win10年度更新开发必备:VS2015 Update 1正式版下载汇总
    Win10年度更新开发必备:VS2015 Update 2正式版下载汇总
  • 原文地址:https://www.cnblogs.com/xugang/p/1022368.html
Copyright © 2020-2023  润新知