views:

2469

answers:

3

I have ig:TemplateDataField that contains label. In InitializeRow event handler I try to find that label with e.Row.FindControl but I get null.

I was not able to find another way to find my label. How to look for controls in WebDataGrid rows during InitializeRow event?

A: 

Below is a solution that should work. note: Code is for an Infragistics UltraWebGrid control. The WebDataGrid control is the UltraWebGrid's successor.

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 code:

<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>
mathijsuitmegen
A: 

You have to specify the column that you want to search in like e.Row.Items[0].FindControl("ControlID") where 0 the column index.

Pr0fess0rX
A: 

I found your article very useful. Could you please tell how to do the same in Javascript.I have a dropdownlist inside the TemplatedColumn. I need to set the list items differently for each row. This needs to be done in the Javascript. Could you please help.

Uma

related questions