asp.net控件(1)Repeater

 1. 通过Repeater和数据源创建表格

    <AlternatingItemTemplate>属性可以控制单元格交替显示不同的背景颜色

                   <table width="95%" align="center" bgcolor="#badde9" border="0" cellspacing="1" cellpadding="1"
                            style="margin-top: 15px">
                            <tbody>
                                <tr>
                                    <td width="16%" height="24" align="center" class="a2" background="../../image/ttg.gif"
                                        bgcolor="#dae8ed">
                                        序号
                                    </td>
                                    <td width="16%" align="center" class="a2" background="../../image/ttg.gif" bgcolor="#dae8ed">
                                        服务供应商
                                    </td>
                                    <td width="16%" align="center" class="a2" background="../../image/ttg.gif" bgcolor="#dae8ed">
                                        服务项目名称
                                    </td>
                                    <td width="16%" align="center" class="a2" background="../../image/ttg.gif" bgcolor="#dae8ed">
                                        客户姓名
                                    </td>
                                    <td width="16%" align="center" class="a2" background="../../image/ttg.gif" bgcolor="#dae8ed">
                                        创建时间
                                    </td>
                                    <td align="center" class="a2" background="../../image/ttg.gif" bgcolor="#dae8ed">
                                        操作
                                    </td>
                                </tr>
                                <asp:Repeater ID="rpt1" runat="server" 
                                    onitemdatabound="rpt1_ItemDataBound">
                                    <ItemTemplate>
                                        <tr>
                                            <td height="24" bgcolor="#fafafa" align="center">
                                                <%= number + (pageItems.CurrentPageIndex - 1) * pageItems.PageSize%>
                                                <% number++; %>
                                            </td>
                                            <td bgcolor="#fafafa" align="center">
                                                <%# DataBinder.Eval(Container.DataItem, "ServiceObjectName")%>
                                            </td>
                                            <td bgcolor="#fafafa" align="center">
                                                <%# DataBinder.Eval(Container.DataItem, "ServiceProjectName")%>
                                            </td>
                                            <td bgcolor="#fafafa" align="center">
                                                <%# DataBinder.Eval(Container.DataItem, "ClientName")%>
                                            </td>
                                            <td bgcolor="#fafafa" align="center">
                                                <%#Beyondbit.OA.Community.Common.Format.ShowTime(Eval("CreateTime"), "yyyy-MM-dd HH:mm:ss")%>
                                            </td>
                                            <td bgcolor="#fafafa" align="center">
                                                <asp:HyperLink runat="server" ID="reviewHref" Text="回访" CssClass="button blue small"/>
                                                <asp:Label ID="lblStatus" runat="server" Text="已完成" />
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                    <AlternatingItemTemplate>
                                        <tr>
                                            <td height="24" bgcolor="#f1f6f8" align="center">
                                                <%= number + (pageItems.CurrentPageIndex - 1) * pageItems.PageSize%>
                                                <% number++; %>
                                            </td>
                                            <td bgcolor="#f1f6f8" align="center">
                                                <%# DataBinder.Eval(Container.DataItem, "ServiceObjectName")%>
                                            </td>
                                            <td bgcolor="#f1f6f8" align="center">
                                                <%# DataBinder.Eval(Container.DataItem, "ServiceProjectName")%>
                                            </td>
                                            <td bgcolor="#f1f6f8" align="center">
                                                <%# DataBinder.Eval(Container.DataItem, "ClientName")%>
                                            </td>
                                            <td bgcolor="#f1f6f8" align="center">
                                                <%#Beyondbit.OA.Community.Common.Format.ShowTime(Eval("CreateTime"), "yyyy-MM-dd HH:mm:ss")%>
                                            </td>
                                            <td bgcolor="#f1f6f8" align="center">
                                                <asp:HyperLink runat="server" ID="reviewHref" Text="回访" CssClass="button blue small"/>
                                                <asp:Label ID="lblStatus" runat="server" Text="已完成" />
                                            </td>
                                        </tr>
                                    </AlternatingItemTemplate>
                                    <FooterTemplate>
                                        <tr id="Tr1" runat="server" visible='<%#bool.Parse((rptUnAccetpPhone.Items.Count==0).ToString())%>'>
                                            <td colspan="6" height="24" align="center" class="a2">
                                                暂无数据!
                                            </td>
                                        </tr>
                                    </FooterTemplate>
                                </asp:Repeater>
                            </tbody>
                        </table>
View Code

2. 让Repeater只重复显示一次

protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                if (e.Item.ItemIndex > 1)
                    e.Item.Visible = false;
            }
        }
View Code

3. Repeater控件没数据时显示"找不到任何数据" 

<FooterTemplate>  
    <asp:Label ID="lbEmpty" Text="找不到任何数据!" ForeColor="Red"  runat="server" Visible='<%#bool.Parse((YourRepeaterID.Items.Count==0).ToString())%>'>
    </asp:Label>  
</FooterTemplate>  
View Code

 

posted @ 2013-07-19 13:42  quanzhan  阅读(221)  评论(0编辑  收藏  举报