我们如何防止转发器中的标签被覆盖?

时间:2013-04-10 11:06:50

标签: asp.net

我使用转发器控件来显示在ItemDataBound事件期间绑定了三个项目的数据代码的问题是转发器的所有行中显示的最后一条记录覆盖了已存在的值,我该如何停止这个?我使用这样的代码

.aspx.cs代码

DataSet dsJobCardHistory =new DataSet();
double dcPriceIncl;
double dcPriceExcl; 
double dcTax;

protected void Job_History()
{ 
   dsJobCardHistory = objReportManager.Get_JobCard_History(strCustNo, strTranId);
}

protected void repJobCard_ItemDataBound(object sender, RepeaterItemEventArgs e)
{

  for (int i = 0; i < dsJobCardHistory.Tables[0].Rows.Count;i++)

   {
     dcPriceIncl = Convert.ToDouble(dsJobCardHistory.Tables[0].Rows[i][6].ToString());
     dcTax = dcPriceIncl * 0.14;
     dcPriceExcl = dcPriceIncl - dcTax;

      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType==
                                ListItemType.AlternatingItem)
       {
            ((Label)e.Item.FindControl("lblRepPrice")).Text = 
             Convert.ToString(dcPriceExcl);
            ((Label)e.Item.FindControl("lblRepTax")).Text = 
             Convert.ToString(dcTax);
            ((Label)e.Item.FindControl("lblRepTotal")).Text = 
              Convert.ToString(dcPriceIncl);
       }                
    }

}

.aspx代码

<asp:Repeater ID="repJobCard" runat="server" onitemdatabound="repJobCard_ItemDataBound">
     <td align="center" width="15%">                                   
          <font style="font-size:14px">
               <strong>
                   <asp:Label ID="lblRepPrice" runat="server" Text="">
                   </asp:Label>
               </strong>
          </font>
    </td>
    <td align="center" width="15%">                                   
        <font style="font-size:14px">
            <strong>
               <asp:Label ID="lblRepTax" runat="server" Text="">
               </asp:Label>
            </strong>
        </font>
    </td>
    <td align="center" width="15%">                                   
        <font style="font-size:14px">
              <strong>
                  <asp:Label ID="lblRepTotal" runat="server" Text="">
                  </asp:Label>
              </strong>
        </font>
   </td>

1 个答案:

答案 0 :(得分:0)

尝试这样的事情

protected void Job_History()
{ 
   dsJobCardHistory = objReportManager.Get_JobCard_History(strCustNo, strTranId);
   repJobCard.DataSource = dsJobCardHistory ;
   repJobCard.DataBind();
}

protected void repJobCard_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    string price = DataBinder.Eval(e.Item.DataItem, "dcPriceExcl").ToString(); // dcPriceExcl -- or whatever the column names are for your data.
    string tax = DataBinder.Eval(e.Item.DataItem, "dcTax").ToString();
    string total = DataBinder.Eval(e.Item.DataItem, "dcPriceIncl").ToString();

    Label lblRepPrice = e.Item.FindControl("lblRepPrice") as Label;
    Label lblRepTax = e.Item.FindControl("lblRepTax") as Label;
    Label dcPriceIncl = e.Item.FindControl("dcPriceIncl") as Label;

    lblRepPrice.Text = price;
    lblRepTax.Text = tax;
    dcPriceIncl.Text = total;
}

并且

<asp:Repeater ID="repJobCard" runat="server" onitemdatabound="repJobCard_ItemDataBound">
    <ItemTemplate>
        All of your HTML
    </ItemTemplate>
 </asp:Repeater>