This is a migrated thread and some comments may be shown as answers.

Cannot find a column with UniqueName 'FileID' on my TemplateColumn

1 Answer 608 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 11 Jun 2014, 06:27 PM
Hi, I have a template column titled 'FileID' and am trying to access it. Unfortunately whenever it comes across a template column, it will error out saying that FileID is not a column.

ASPX:

<telerik:GridTemplateColumn DataField="FileID" HeaderText="File / Link" HeaderStyle-Width="55px" SortExpression="FileID" HeaderStyle-ForeColor="White" AllowFiltering="false" ItemStyle-Width="20%" ItemStyle-Wrap="true" ShowSortIcon="false">
                            <ItemTemplate>
                                <asp:HyperLink ID="hlLink" runat="server" Target="_blank" Visible="false"></asp:HyperLink>
                            </ItemTemplate>
</telerik:GridTemplateColumn>

From this you can see that my GridTemplateColumn's DataField is named "FileID"

VB.NET:
For Each col In dg.Columns
                If (col.GetType() Is GetType(Telerik.Web.UI.GridBoundColumn)) Then
                    If col.HeaderText = ColumnName Then
                        If HideOrShow Then
                            dg.MasterTableView.GetColumn(col.DataField).Display = True
                        Else
                            dg.MasterTableView.GetColumn(col.DataField).Display = False
                        End If
                    End If
                Else
                    If (col.GetType() Is GetType(Telerik.Web.UI.GridTemplateColumn)) Then
                        If HideOrShow Then
                            dg.MasterTableView.GetColumn(col.DataField).Display = True
                        Else
                            dg.MasterTableView.GetColumn(col.DataField).Display = False
                        End If
                    End If
                End If
            Next

And this is what throws the error:  dg.MasterTableView.GetColumn(col.DataField).Display = True underneath the TemplateColumn part.

Did I not name the column correctly? I thought DataField was what I used, and it works on the rest of the BoundColumns. Can I get some pointers here?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Alexander
Top achievements
Rank 1
answered on 11 Jun 2014, 07:41 PM
Apparently the GridTemplateColumns act differently from GridBoundColumns. While this method works for GridBoundColumn, you actually have to use FindControl() instead for Templates.

For example: finding data values of the TemplateColumn would need FindControl("FileID") and so forth. 
Tags
Grid
Asked by
Alexander
Top achievements
Rank 1
Answers by
Alexander
Top achievements
Rank 1
Share this question
or