简体   繁体   English

如何访问DataList中的未绑定项目

[英]How to access unbounded Item in DataList

I'm using a DataList . 我正在使用DataList The ItemTemplate is bounded. ItemTemplate是有界的。 I add a HeaderTemplate , and put it inside a table, which will be needed to contain dynamic lables which I add in each FormLoad. 我添加了HeaderTemplate ,并将其放在表中,该表将包含包含在每个FormLoad中添加的动态标签。 I don't want the header to be bounded. 我不希望标题受到限制。

I'm trying to access this table , but it shows me that this table doesn't exist or can't be accessible. 我正在尝试访问此表,但它向我显示该表不存在或无法访问。

if (this.TableCategories.Rows.Count == 0 || 
    this.TableCategories.Rows[this.TableCategories.Rows.Count - 1].Cells.Count == 5)
{
    TableRow newRow = new TableRow();
    this.TableCategories.Rows.Add(newRow);
}


<asp:DataList ID="DataListProducts" runat="server" RepeatDirection="Horizontal" 
  OnItemCommand="DataListProducts_ItemCommand" Height="200px" Width="100%" 
  BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
  CellPadding="0" GridLines="Vertical" RepeatColumns="6">

    <HeaderTemplate>
        <asp:Table ID="TableCategories" runat="server" BorderColor="Black"  
          CssClass="floatRight" BorderStyle="Inset" BorderWidth="2px" GridLines="Both">
        </asp:Table>
    </HeaderTemplate>

Thanks 谢谢

Your DataList encapsulates all of its controls. 您的DataList封装了其所有控件。 They are not know at page level. 他们在页面级别不知道。

Assuming all controls will always be there, you may try : 假设所有控件都将始终存在,您可以尝试:

var myTable = (Table)DataListProducts
             .Controls[0]
             .FindControl("TableCategories");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM