I am trying to modify existing code that is similar to the following:
What I want to do is create a link so that when the "Total Cost" Header is clicked, another aspx page will open up. Is there a way to do this?
Thanks!
There are two options for this that I can think of.
One is to handle the ColumnHeaderClick event of the grid, confirm that the header that was clicked is the one you want to respond to, and in there using window.open() to open up the new page.
The other is to set the Caption of your grid to an HTML anchor tag, so that it's processed by the client as a hyperlink. This will only work if the column's HTMLEncodeContent property is set to false, which it is by default.
ch.Caption = "<a href='http://infragistics.com'>Total Cost</a>";
I got the link to work with the method above. The problem is now, when I try to export the page to Excel, the columns with the link header shows the following:
<a target='_blank' href ="TotalCost.aspx">Total Cost $</a>
It does not show "Total Cost" and none of the values in that column are displayed, or anything else that comes in the grid after that column.
What is the best way to handle this?
To display just the text in the Excel file, you'll need to use the events of the WebGridExcelExporter. I suggest using the HeaderCellExported event - you can get a reference to the Excel cell using e.Workbook, e.Worksheet, e.CurrentRowIndex, and e.CurrentCellIndex. This lets you view what was exported, and then you can strip out the HTML from the text, or otherwise modify it how you want.
If other values aren't being displayed, however, then this sounds like something may be wrong. If the problem persists after you modify the Excel cell's text, then there may be a bug somewhere. If you can reproduce this in a small sample application, please submit a support request and attach that sample, so a Developer Support Engineer can investigate further.