C# 以编程方式分配TableCell.AssociatedHeaderCellID

C# 以编程方式分配TableCell.AssociatedHeaderCellID,c#,asp.net,C#,Asp.net,我无法在TableCell上分配关联的HeaderCellid 我有一个扩展的GridView,我在其中创建了一个单元格,并将其添加到表的一行,因此: newCell = new TableHeaderCell() { ID = "SomeUniqueHeading" }; newRow.Cells.Add(newCell); 然后在几行之后尝试添加与HeaderCellid关联的现有单元格之一的id: existingCell.AssociatedHeaderCellID = new []

我无法在TableCell上分配关联的HeaderCellid

我有一个扩展的GridView,我在其中创建了一个单元格,并将其添加到表的一行,因此:

newCell = new TableHeaderCell() { ID = "SomeUniqueHeading" };

newRow.Cells.Add(newCell);
然后在几行之后尝试添加与HeaderCellid关联的现有单元格之一的id:

existingCell.AssociatedHeaderCellID = new []{ newCell.ID};
但是当页面呈现时,我得到了一个HttpUnhandledException,表示没有找到作为相关标头单元格列出的单元格SomeUniqueHeading

我试过使用

existingCell.AssociatedHeaderCellID = new []{ newCell.ClientID};
但结果是一样的

我在谷歌上受到了攻击,没有,似乎真的在做任何我没有做的事情,而且这些都是毫无用处的

你知道我该怎么做吗

下面是ASP标记的示例

<%@ Register TagPreFix="aspex" Namespace="AspExtensions" Assembly="AspExtensions"%>

<aspex:ExtendedGridView ID="linesGridView" runat="server" AutoGenerateColumns="False"  GridLines="None" CssClass="lineTable" ConfigGroupName="lineGridColumns">
    <HeaderStyle CssClass="lineHeaderRow" />
    <AlternatingRowStyle CssClass="row" />
    <RowStyle CssClass="alternatingRow" />
    <Columns>
        <aspex:ExtendedBoundField DataField="DataField1" HeaderText="DataField1Header" SortExpression="DataField1" ConfigElementName="dataField1" />
        <aspex:ExtendedTemplateField HeaderText="DataField2Header" Visible="false" ConfigElementName="dataField2">
            ...
        </aspex:ExtendedTemplateField>
        .
        .
        .
    </Columns>
</aspex:ExtendedGridView>

如果您尝试不使用ID会发生什么?我在这里有点生疏,但我认为ID为的控件需要在页面生命周期的早期添加。使用existingCell.AssociatedHeaderCellID=new[]{newCell}会给我一个编译错误。。。无法将类型“…TableCell”隐式转换为“string”。如果需要提前输入,您知道有多早吗?请暂时注释掉现有的cell.AssociatedHeaderCellID。查看页面是否已加载。如果确实添加了新的标题单元格,但没有添加相关的分配,请查看页面是否加载。我预测它会在这里失败。我认为您需要在Page Init事件中或其周围添加单元格。请阅读更多有关的内容。您是否也可以将您的GridView标记包括在内。@JonP我已经为您添加了一些。。。