【问题标题】:How to get the total count of rows in a repeater?如何获取转发器中的总行数?
【发布时间】:2013-04-01 19:29:26
【问题描述】:

我正在使用Repeater控件显示数据,数据源包含多条记录 显示在中继器中,我需要的是获取两个列表项的差异并将其分配给另一个列表项,我使用下面提到的代码对第一条记录工作正常,但不显示所有记录

aspx.cs 代码

DataSet dsJobCardHistory =new DataSet(); 
double dcPriceIncl;
double dcPriceExcl;
double dcTax;
protected void Job_History()
{

    dsJobCardHistory = objReportManager.Get_JobCard_History(strCustNo, strTranId);

     dcPriceIncl = Convert.ToDouble(dsJobCardHistory.Tables[0].Rows[0][6].ToString());
      dcTax = dcPriceIncl * 0.14;
      dcPriceExcl = dcPriceIncl - dcTax;
}
protected void repJobCard_ItemDataBound(object sender, RepeaterItemEventArgs e)
{     
       if (e.Item.ItemType == ListItemType.Item)
            {
            ((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 代码

 <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>

【问题讨论】:

  • 你的问题不清楚
  • 我需要减去这个中继器的两个项目 lblRepTotal 和 lblRepPrice 的值并将值分配给下一个项目 lblRepTax,代码仅适用于第一行,我需要以某种方式获取计数行,以便我可以分别对其进行迭代。
  • 计算部分的代码在哪里
  • 您发布的示例代码不会更精确
  • dcPriceIncl = Convert.ToDouble(dsJobCardHistory.Tables[0].Rows[0][6].ToString()); dcTax = dcPriceIncl * 0.14; dcPriceExcl = dcPriceIncl - dcTax;

标签: asp.net repeater


【解决方案1】:

正如你所说,它只是第一次工作,所以替换你的这一行

if (e.Item.ItemType == ListItemType.Item)

与....

 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)

【讨论】:

    【解决方案2】:
    1. [xp:repeat] 一个 ID 值,例如idvaluestring
    2. 在 SSJS 中使用 getComponent("idvalueString").getRowCount()

    RepeatControl 的类是:

    com.ibm.xsp.component.xp.XspDataIterator

    <xp:repeat var="voyageChoicesCollection"
    indexVar="voyageChoicesCollectionIndex" 
    value="#{ProfileListRepeat}"
    id="voyageChoicesCollectionID"> 
    
    var vccID:com.ibm.xsp.component.xp.XspDataIterator = getComponent("voyageChoicesCollectionID");
    vccID.getRowCount() 
    

    【讨论】:

      猜你喜欢
      • 2017-10-02
      • 2012-08-06
      • 2020-11-15
      • 1970-01-01
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      相关资源
      最近更新 更多