I have the following code in a WebHierarchicalDataGrid's InitializeRow event in order to format html links when I don't know if or where they will be in the datatable. It's been working great for years, but within the last year something has broken, and it no longer formats the first row. All other rows are formatted fine. I can't know for sure which version this first popped up in, but I know it exists in 12.2.20142.2146.
If e.Row.Items.Count > 0 Then
For i As Integer = 0 To e.Row.Items.Count - 1
If e.Row.Items(i).Text.ToLower.Contains("href=") Then
Dim oColumn As BoundDataField = CType(e.Row.Items(i).Column, BoundDataField)
oColumn.HtmlEncode = False
oColumn.CssClass = "nowrapHTML"
End If
Next
Hello,
Thank you for contacting Infragistics Developer Support!
I was not able to reproduce the behaviour that you're seeing on your side. I have attached the sample project I used to test this. Please test this project on your side; whether or not it works correctly may help indicate the nature of this issue. If this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.Please let me know if I can provide any further assistance.
Thanks so much! I see using debug that you are correct, and the event is in fact firing. I'm sorry for assuming it wasn't. It appears that it's the oColumn.HtmlEncode that is not working correctly on the first row. The event is firing, and HtmlEncode is set to false, other rows display links properly, but the first row does not, even if it's identical to other rows.
In your example code, you could add html, such as
row.SetField(Of String)("Address", "<a href=""http://es.infragistics.com"">Paris</a>")
row.SetField(Of String)("Address", "<a href=""http://es.infragistics.com"">Rome</a>")
And then test for href= by:
And you will see the problem.
Hello Clinton,
Did you look at my sample?
I was able to break your sample by enabling filtering. I'm not sure if that's the only difference, so I'm continuing to test my app vs. your sample. We definitely need filtering.
In order to work with filtering you can change the selector to be td.nowrap[role="gridcell"] and this way it will not be matching the filtering cell and the header, then you can get the 0 element from the collection.
function WebHierarchicalDataGrid_Initialize(sender, eventArgs) { var $encodedCell = $($('td.nowrapHTML[role="gridcell"]')[0]); $encodedCell.html($encodedCell.text()); }
Let me know if you need further assistance.
Will this bug be resolved in an upcoming service release? As I said, our module is dynamic, and has many possible configurations. Your workaround is not going to address them all. I'd much rather the grid just work as designed.
You can set HtmlEncode to false for the entire column if it is containing only hyperlinks as so.
Private Sub WebHierarchicalDataGrid1_InitializeRow(sender As Object, e As Infragistics.Web.UI.GridControls.RowEventArgs) Handles Grid.InitializeRow Dim oColumn As BoundDataField = CType(e.Row.Items(1).Column, BoundDataField) oColumn.HtmlEncode = False oColumn.CssClass = "nowrapHTML" End Sub
If this workaround is not possible for you can decode the first row by using HtmlDecode method of HttpUtility.
Private Sub WebHierarchicalDataGrid1_InitializeRow(sender As Object, e As Infragistics.Web.UI.GridControls.RowEventArgs) Handles Grid.InitializeRow If e.Row.Items.Count > 0 Then For i As Integer = 0 To e.Row.Items.Count - 1 If e.Row.Items(i).Text.ToLower.Contains("href=") Then Dim oColumn As BoundDataField = CType(e.Row.Items(i).Column, BoundDataField) oColumn.HtmlEncode = False oColumn.CssClass = "nowrapHTML" If e.Row.Index = 0 Then e.Row.Items(i).Text = HttpUtility.HtmlDecode(e.Row.Items(i).Text) End If End If Next End If End Sub
I am glad that I have managed to help you.
Please let me know if I may be of further assistance.
Thank you for choosing our components!
This second method worked for me. Thank you!