2

我有 ig:TemplateDataField 包含标签。在 InitializeRow 事件处理程序中,我尝试使用 e.Row.FindControl 查找该标签,但我得到空值。

我无法找到另一种方法来找到我的标签。如何在 InitializeRow 事件期间在 WebDataGrid 行中查找控件?

4

2 回答 2

2

您必须指定要搜索的列,例如e.Row.Items[0].FindControl("ControlID")0索引的位置。

于 2009-11-12T09:00:18.383 回答
1

下面是一个应该有效的解决方案。注意:代码用于 Infragistics UltraWebGrid 控件。WebDataGrid 控件是 UltraWebGrid 的继承者。

C#:

protected void UltraWebGridCustomers_InitializeRow(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
{
    TemplatedColumn col = (TemplatedColumn)e.Row.Cells.FromKey("HyperLinkEmailColumn").Column;
    CellItem cellItem = (CellItem)col.CellItems(e.Row.Index);
    HyperLink hyperLinkEmail = (HyperLink)cellItem.FindControl("HyperLinkSendEmail");
    hyperLinkShowDetails.Attributes.Add("onclick", "alert('This is the email link');");
}

VB.NET:

Private Sub UltraWebGridCustomers_InitializeRow(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.RowEventArgs) Handles UltraWebGridCustomers.InitializeRow
        Dim col As TemplatedColumn = CType(e.Row.Cells.FromKey("HyperLinkEmailColumn").Column, TemplatedColumn)
        Dim cellItem As CellItem = CType(col.CellItems(e.Row.Index), CellItem)
        Dim hyperLinkEmail As HyperLink = CType(cellItem.FindControl("HyperLinkSendEmail"), HyperLink)
        hyperLinkShowDetails.Attributes.Add("onclick", "alert('This is the email link');")
End Sub

ASP代码:

<infragistics:UltraWebGrid ID="UltraWebGridCustomers" runat="server">
    <Bands>
        <infragistics:UltraGridBand BaseTableName="Customers" Key="BandCustomers">
            <Columns>
                ...
                <infragistics:UltraGridColumn Key="NameColumn" BaseColumnName="Name" IsBound="True">
                    <Header Caption="Name">
                    </Header>
                </infragistics:UltraGridColumn>
                <infragistics:UltraGridColumn Key="EmailColumn" BaseColumnName="Email" IsBound="True">
                    <Header Caption="Email Address">
                    </Header>
                </infragistics:UltraGridColumn>
                <infragistics:TemplatedColumn Key="HyperLinkEmailColumn">
                    <CellTemplate>                        
                        <asp:HyperLink ID="HyperLinkSendEmail" NavigateUrl='<%# "~/EmailForm.aspx?email=" & DataBinder.Eval(Container.DataItem,"Email")%>' ToolTip="Send Email" runat="server" />
                    </CellTemplate>
                </infragistics:TemplatedColumn>
                ...
            </Columns>
            <AddNewRow View="NotSet" Visible="NotSet">
            </AddNewRow>                            
        </infragistics:UltraGridBand>
    </Bands>
    ...
</infragistics:UltraWebGrid>    
于 2009-03-17T10:28:41.770 回答