I want a hyperlink on the column header of a WebDataGrid. Does anybody know how this can be done?
ThanksNick
Hello Nick,
I am glad that you have been able to resolve your issue. Feel free to contact me if you need any further support.
Great, just what I needed Vasya.
Thank youNick
Hello DataPA
I am attaching a VB sample demonstrating how a link header template may be created dynamically in WebDataGrid. Below is the relevant code used:
Private Class CustomItemTemplate Implements ITemplate #Region "ITemplate Members" Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn Dim hlink As New HyperLink() hlink.ID ="hyp1" hlink.Text ="This is the hyperlink" hlink.NavigateUrl ="http://ko.infragistics.com/" hlink.Target ="_blank" container.Controls.Add(hlink) End Sub
Private Class CustomItemTemplate
Implements ITemplate
#Region "ITemplate Members"
Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
Dim hlink As New HyperLink()
hlink.ID ="hyp1"
hlink.Text ="This is the hyperlink"
hlink.NavigateUrl ="http://ko.infragistics.com/"
hlink.Target ="_blank"
container.Controls.Add(hlink)
End Sub
Please let me know if you have any questions.
Hi Nikifor,
Thanks very much for your answer. The grid is actually dynamically created using code on the server. i.e;
Dim DataGrid As New Infragistics.Web.UI.GridControls.WebDataGridParent.Controls.Add(DataGrid)
DataGrid.AutoGenerateColumns = False DataGrid.DataSource = DataTable DataGrid.Columns.Clear()
Dim DataColumn As System.Data.DataColumn For Each DataColumn In DataTable.ColumnsDim BoundField As New Infragistics.Web.UI.GridControls.BoundDataField(True)
BoundField.DataFieldName = DataColumn.ColumnName BoundField.Key = DataColumn.ColumnName DataGrid.Columns.Add(BoundField) BoundField.Header.Text = GetColumnLabel(DataColumn.ColumnName)
Next
I'm struggling to convert the markup to code building this structure using the object model. Any help much appreciated.
Hello Nick,Thank you for posting in our community. This is actually quite easy to achieve. You have to just use header template. This is a code demonstrating how to achieve the desired look of the grid:
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px" AutoGenerateColumns="False"> <Columns> <ig:BoundDataField Key="id" DataFieldName="id" Header-Text="id"><Header Text="id" TemplateId="Template1"></Header> </ig:BoundDataField> </Columns> <Templates> <ig:ItemTemplate ID="WebDataGrid1Template1" runat="server" TemplateID="Template1"> <Template> <a href="http://ko.infragistics.com/">Visit Infragistics</a> </Template> </ig:ItemTemplate> </Templates> </ig:WebDataGrid>