我有ig:TemplateDataField包含label。 在InitializeRow事件处理程序中,我尝试使用e.Row.FindControl查找该标签,但我得到null。
我无法找到另一种找到我的标签的方法。 如何在InitializeRow事件期间查找WebDataGrid行中的控件?
答案 0 :(得分:2)
您必须指定要搜索的列,例如e.Row.Items[0].FindControl("ControlID")
其中0
列索引。
答案 1 :(得分: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
Aspx代码:
<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>