0

我使用转发器控件来显示在 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>
4

1 回答 1

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>
于 2013-04-10T14:43:04.447 回答