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,
Setting url and HTML elements like that is bad practice and should be avoided, because it opens opportunities for XSS attachs.
Please consider using item templates for the following. For more refer to => http://help.infragistics.com/Help/Doc/ASPNET/2014.2/CLR4.0/html/WebHierarchicalDataGrid_Using_Item_Template.html
I have tested this and the event still fires. Provide sample project replicating the issue you have experienced.
Sorry, I missed your earlier post.
I can understand the cross scripting concern. This app displays reports written in sql on our customer portal, and allows them to be added/modified without the need to modify code. We've had this app in production for years, and it was the primary reason for purchasing Infragistics controls back in 2007, and continuing to renew each year. Some of the reports in questions contain links to other reports in the same customer portal, and we are in control of every report, so xss is not a concern for us. There are well over 400 reports in production, though only a fraction utilize this href feature.
Please keep in mind that this has worked fine for us since switching to the WebHierarchicalDataGrid when the original WebGrid was discontinued several years ago, and I believe the code itself was from an old Infragistics post or documentation. Even now this method works great for every row EXCEPT the first row, so is obviously a bug that was introduced in one of the last few versions.
I have attached an example project which demonstrates the issue. It's based on your original project with some minor changes and reproduced the problem reliably.
I am not able to see the result the event is fired 4 time exactly the same amount as the rows are.
I have modified the sample so it prints the record it for which it is being fired.
I have tested this in Chrome, Firefox and IE 8-11.
Please let me know if I am missing anything else for reproducing the issue.
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!
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
Thank you for reporting this.
I have asked our engineering staff to examine this further. To ensure that it will receive attention, I have logged this behavior in our internal tracking system with a Development ID of 192575. A support case is created on your behalf with number CAS-152729-Y3X0N9, so that you can be notified when the this is fixed. You can find your active cases under Account - Support Activity in our website. Select your ticket and go to Development Issues tab to view the status of related development issues.
Let me know if I may be of 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.