We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to place a weblink in the header of GridGroupingControl

I wanted to place a link to another page on the header of one column (and only on the header, not on every row of the column) of my GridGroupingControl.

When clicked, it should call a new page.

The columns are inserted dynamically, so i'm using "GridColumnDescriptor" to place the columns in my GridGroupingControl.

My code is as described below, but when i click on the header, it won't open the page, it also ignore the width:

GridColumnDescriptor col = new GridColumnDescriptor();
col.Name = "Find";
col.Width = 150;
col.Appearance.ColumnHeaderCell.CellType = "Link";
col.Appearance.ColumnHeaderCell.Tag = "http://www.syncfusion.com/FAQ/WinForms";

this.ggc.TableDescriptor.Columns.Add(col);
this.ggc.TableDescriptor.VisibleColumns.Add(col.Name);



3 Replies

RP Rekha P Syncfusion Team January 9, 2009 06:43 AM UTC

Hi Daniel,

Thank you for your interest in Syncfusion Products.

To make a column header as hyperlink, you can create a TemplateClass to add a HyperLink instance. Please refer the code snippet below to achieve this.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridColumnDescriptor col = new GridColumnDescriptor();
col.Name = "Find";
col.Width = 150;

this.GridGroupingControl2.TableDescriptor.Columns.Add(col);
this.GridGroupingControl2.TableDescriptor.VisibleColumns.Add(col.Name);
}
this.GridGroupingControl2.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(GridGroupingControl2_QueryCellStyleInfo);
}

void GridGroupingControl2_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.ColumnHeaderCell)
{
if (e.TableCellIdentity.Column.Name == "Find")
{
HyperLink hypLink = new HyperLink();
hypLink.ID = "Find1";
hypLink.Text = e.Style.CellValue.ToString();
hypLink.NavigateUrl = "http://www.syncfusion.com/FAQ/WinForms";
hypLink.Target = "_blank";

TemplateClass mytemp = new TemplateClass(hypLink);
e.TableCellIdentity.Column.HeaderTemplate = mytemp;
e.Handled = true;
}
}
}

public class TemplateClass : ITemplate
{
private Control m_ctrlChildControl = null;
public TemplateClass(Control ctrlChildControl)
{
m_ctrlChildControl = ctrlChildControl;
}

public void InstantiateIn(Control container)
{
container.Controls.Add(m_ctrlChildControl);
}
}


Also please refer the sample below which illustrates the column hiding and then delete the selected record.

http://websamples.syncfusion.com/samples/Grid.Web/6.4.0.15/F78876_HeaderCol_HyperLink/main.htm

Thank you for being patient and please let me know if this sample helps you.

Thanks,
Rekha



DS Daniel Santos de Carvalho January 12, 2009 12:27 PM UTC

Worked very well, thanks Rekha



RP Rekha P Syncfusion Team January 12, 2009 12:55 PM UTC

Hi Daniel,

Thanks for the update and please let me know if you have any other concerns.

Thanks,
Rekha


Loader.
Live Chat Icon For mobile
Up arrow icon