Repeater的用法

来源:互联网 发布:mac和芭比布朗粉底 编辑:程序博客网 时间:2024/05/20 04:13

 

          <asp:Repeater ID="Repeater_Price" runat="server" OnItemDataBound="Repeater_Price_ItemDataBound">
          <ItemTemplate>
            <tr bgcolor="white">
            <td style="height: 25px">&nbsp;<font color="red"><strong><asp:Label ID="labBigCategory" runat="server"></asp:Label></strong></font></td>
            <td style="height: 25px">&nbsp;<asp:Label ID="labSmallCategory" runat="server"></asp:Label></td>
            <td style="height: 25px">&nbsp;<asp:Label ID="labUnit" runat="server"></asp:Label></td>
            <td style="height: 25px">&nbsp;<asp:Label ID="labNum" runat="server"></asp:Label></td>
            <td style="height: 25px">&nbsp;<asp:Label ID="labPrice" runat="server"></asp:Label></td>
            <td style="height: 25px">&nbsp;<asp:Label ID="labTotalPrice" runat="server"></asp:Label></td>
            <td style="height: 25px">&nbsp;<asp:Label ID="labRemarks" runat="server"></asp:Label></td>
          </tr>
          </ItemTemplate>
          </asp:Repeater>

 

 

        this.Repeater_Price.DataSource = ServiceLocator.ProjectService.GetProjectPriceByProId(proId);
        this.Repeater_Price.DataBind();

 

    /// <summary>
    /// 初始化绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Repeater_Price_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            ProjectPrice proPrice = (ProjectPrice)e.Item.DataItem;

            Label l_BigCategory = (Label)e.Item.FindControl("labBigCategory");
            l_BigCategory.Text = proPrice.ProjectBigCate;

            Label l_SmallCategory = (Label)e.Item.FindControl("labSmallCategory");
            l_SmallCategory.Text = proPrice.ProjectSmallCate;

            Label l_Unit = (Label)e.Item.FindControl("labUnit");
            l_Unit.Text = proPrice.Unit;

            Label l_Num = (Label)e.Item.FindControl("labNum");
            l_Num.Text = Convert.ToString(proPrice.Num);

            Label l_Price = (Label)e.Item.FindControl("labPrice");
            l_Price.Text =Convert.ToString(proPrice.ProjectCountPrice);

            Label l_TotalPrice = (Label)e.Item.FindControl("labTotalPrice");
            l_TotalPrice.Text = Convert.ToString(proPrice.ProjectCountPrice * proPrice.Num);

            Label l_Remarks = (Label)e.Item.FindControl("labRemarks");
            l_Remarks.Text = proPrice.Remarks;

        }
   
    }