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

DataTextField on GridHyperLinkColumn

5 Answers 360 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Keith Henkel
Top achievements
Rank 1
Keith Henkel asked on 02 Jan 2008, 10:35 PM
The DataTextField property of the GridHyperLinkColumn doesn't seem to support values of nested objects such as "InnerObject1.InnerObject2.Property1".

So far I have only gotten it to work with top-level properties.

Is this a known bug?


5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 03 Jan 2008, 08:34 AM
Hi Keith,

Generally only GridBoundColumn supports binding to sub objects at this moment.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Keith Henkel
Top achievements
Rank 1
answered on 03 Jan 2008, 05:55 PM
How would  I bind the Text of the hyperlink then?

I've tried this:

    Protected Sub grid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid.ItemDataBound 
        If e.Item.DataItem IsNot Nothing Then 
            'Set the hyperlink caption 
            DirectCast(e.Item.OwnerTableView.Columns(2), Telerik.Web.UI.GridHyperLinkColumn).Text = DirectCast(e.Item.DataItem, InsightEcosystems.IEReports.IEReport).Tracking.Name 
        End If 
    End Sub 


However the names that get bound do not go into the right data rows.

In a simple example, the collection I'm binding to has two rows. When the grid renders the first row's hyperlink Text is still empty with the code above, and the second row's hyperlink Text is what should appear in the first row.

Further, I've noticed that ItemDataBound gets called 4 times with e.Item.DataItem <> Nothing when there are only 2 items in the collection. When I check e.Item.RowIndex it outputs 2, 3, 4, and 5 on each of the calls even though two rows visually appear in the grid when it renders.


Thanks again
0
Keith Henkel
Top achievements
Rank 1
answered on 04 Jan 2008, 03:42 PM
Nevermind.

Here is the solution for others that have this same problem:

    Protected Sub grid_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles grid.ItemDataBound 
        If TypeOf e.Item Is Telerik.Web.UI.GridDataItem Then 
            Dim gridDataItem As Telerik.Web.UI.GridDataItem = DirectCast(e.Item, Telerik.Web.UI.GridDataItem) 
            DirectCast(gridDataItem("Name").Controls(0), HyperLink).Text = DirectCast(gridDataItem.DataItem, InsightEcosystems.IEReports.IEReport).Tracking.Name 
        End If 
    End Sub 
0
Keith Henkel
Top achievements
Rank 1
answered on 04 Jan 2008, 05:37 PM
I now have a related problem with sorting. As described above, my hyperlink column doesn't contain a DataField value because the value it needs is nested in a sub-object.  I'm having to catch the ItemDataBound event and set the Text on the hyperlink to the value in the nested sub-object.

Because of all of this, sorting doesn't work on the hyperlink column.

Is there a way to catch the SortCommand event and handle it? I'm not sure how.

Unless the other column types will support nested sub-objects VERY soon, it looks like anyone binding to an object hierarchy will just have to loop through them, copy them to an ArrayList, and then bind the grid to that.


0
Sebastian
Telerik team
answered on 07 Jan 2008, 12:28 PM
Hello Keith,

I think that the information from the forum thread linked below can help you implement filtering for your GridHyperlinkColumns when binding to sub-objects:

http://www.telerik.com/community/forums/thread/b311D-ehght.aspx

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Keith Henkel
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Keith Henkel
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or