从Repeater Asp.Net获取行数

时间:2016-04-20 15:32:49

标签: c# asp.net

我尝试在转发器中为其中的每个项目应用删除列。到目前为止,我已经能够在该列的Header Cell中应用该更改,并且还可以在Header之后的第一行应用,如果我将我的代码放在这样:

 An exception of type 'System.InvalidCastException'
 occurred in F_GBA.dll but was not handled in user code

Additional information: Unable to 
cast object of type 'System.Web.UI.DataBoundLiteralControl'
to type 'System.Web.UI.HtmlControls.HtmlTableCell'.

我认为我需要获得Repeater Count才能遍历转发器绑定的行,以便我实现该解决方案。但是,每次我使用for循环运行应用程序时,我都会得到:

 protected void rptBillHeaders_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        RepeaterItem item = e.Item;
        if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rptLineItems = ((Repeater)item.FindControl("rptLineItems"));
            rptLineItems.DataSource = currentBill.LineItemsByXVersion[rowNumber].Sort(BillLineItem.SortColumn.LineItemNumber, System.Data.SqlClient.SortOrder.Ascending);
            rptLineItems.DataBind();

            if (e.Item.Controls.Count >= 5)
            {                   
                for (int i = 1; i <= item.Controls.Count; i++)
                {
                    var XDocColumn = (HtmlTableCell)e.Item.Controls[i];
                    if (lit.BillTypes.COD == "COD")
                    {
                        if (XDocColumn != null)
                        {
                            XDocColumn.Visible = false;
                        }
                    }
                }

            }

            rowNumber++;
        }
}

以下是代码段:

 <asp:Repeater runat="server" ID="rptBillHeaders" OnItemDataBound="rptBillHeaders_ItemDataBound">
    <HeaderTemplate>
        <table width="98%" align="center" class="grid" cellpadding="0" cellspacing="0" style="border:solid 1px #000000; border-top:none 0px #FFFFFF;">
                <tr class="gridHeaderRow">
                    <th>&nbsp</th>
                    <th><asp:Label runat="server" ID="billVersionLabel" ></asp:Label></th> 
                    <th>Action Type</th>
                    <th id="XDocHeader" runat="server">FMMI Doc #</th>
                    <th>X Status</th>
                    <th>Total Amount</th>
                    <th>Submitted By</th>
                    <th>Date Submitted</th>
                    <th>Date Processed</th>
                </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr class="gridRow gridRowThickTopBorder">
            <td style="padding: 5px;">
                    <div id="divBillIcon" align="center" style="text-align:center;" class="icon ui-state-default ui-corner-all">
                        <span class="ui-icon ui-icon-plus"></span>
                    </div>
            </td>
            <td class="Center"><%# ((int)Container.DataItem) %></td>
            <td><%# GetXActionType((int)Container.DataItem) %> </td>
            <td id="XDocColumn" runat="server"><%# GetXDocNumber((int)Container.DataItem) %> </td>
            <%--<td><%# val.get(cache.XStatusDict, currentBill.ProcessedStatusesByXVersion[((int)Container.DataItem)].XStatus, "&nbsp;") %></td>--%>
            <td><%# val.get(cache.BillStatusDict, currentBill.ProcessedStatusesByXVersion[((int)Container.DataItem)].XStatus, "&nbsp;") %></td>
            <td class="Right">$<%# currentBill.LineItemsByXVersion[((int)Container.DataItem)].GetTotalAmount().ToString("N2") %></td>
            <td><%# currentBill.PendingStatusesByXVersion[((int)Container.DataItem)].CreateWebUserName %></td>
            <td><%# convert.ToDateString(convert.ToDateTimeQ(currentBill.PendingStatusesByXVersion[((int)Container.DataItem)].CreateDate)) %></td>
            <td><%# convert.ToDateString(convert.ToDateTimeQ(currentBill.ProcessedStatusesByXVersion[((int)Container.DataItem)].CreateDate)) %></td>
        </tr>

标记代码:

winrpm

任何帮助将不胜感激。

感谢。

0 个答案:

没有答案