This is a migrated thread and some comments may be shown as answers.

LinkButton in a RadGridView

8 Answers 253 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Elver Emilio Cano Cardona
Top achievements
Rank 1
Elver Emilio Cano Cardona asked on 03 May 2010, 02:20 PM
Good morning 

I need help  i have the  version Q1 2010 its the last version and i am trying to add a LinkButton into the RadGridView but i couldn't make it.. there is a option to add a button, image and others components. how i could add a LinkButton
thanks. for your help.
regards
Elver Cano

8 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 04 May 2010, 06:45 PM
Hello Elver Emilio Cano Cardona,

If you need to create a cell with a button you can create a GridViewCommandColumn. For more information you can check this documentation article. However, you can create a custom data cell element which can host all of your desired items. You can read this documentation article if you want to create a custom data cell.

All the best,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Elver Emilio Cano Cardona
Top achievements
Rank 1
answered on 04 May 2010, 07:55 PM
Hello, i know the GridViewCommandColumn but i don´t need it.
I NEED some like GridViewLinkColumn something like that... there is a example to make a link in a cell..
thanks for your help.
regards
elver cano
0
Svett
Telerik team
answered on 05 May 2010, 11:40 AM
Hi Elver Emilio Cano Cardona,

You can achieve the same approach by using GridViewCommandColumn. You need only to subscribe for the CommandCellClick event, where you can process the opening of the link. You can use the following code snippet:

GridViewCommandColumn cmdCol = new GridViewCommandColumn("URL", "URL");
this.radGridView.Columns.Add(cmdCol);

this.radGridView.CommandCellClick += new CommandCellClickEventHandler(radGridView_CommandCellClick);
 
private void radGridView_CommandCellClick(object sender, EventArgs e)
{
    GridCommandCellElement commandCell = sender as GridCommandCellElement;
 
    if (commandCell == null)
    {
        return;
    }
 
    // The format of the link should be http://www.telerik.com
    string link = Convert.ToString(commandCell.Value);
    Process.Start(link);
}


Best wishes,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Elver Emilio Cano Cardona
Top achievements
Rank 1
answered on 05 May 2010, 02:03 PM
I am so greatfull for your help.. but i need change the appearance..i need that it looks like a link and not like button..to do it posible make with telerik.
Very thanks. for your help.
Thanks
Elver Cano
0
Svett
Telerik team
answered on 10 May 2010, 11:48 AM
Hi Elver Emilio Cano Cardona,

You can achieve that by creating a custom data cell. Notice that its value should be a string in URL format. Then you need to replace the default data cell with the custom one. You need to do that in CreateCell event:
private void radGridView_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
    GridViewDataColumn dataColumn = e.Column as GridViewDataColumn;
    if (e.Row is GridDataRowElement && dataColumn != null && dataColumn.UniqueName == "WebSite")
    {
        e.CellType = typeof(GridLinkCellElement);
    }
}

public class GridLinkCellElement : GridDataCellElement
{
    private const string LinkTemplate = @"<html><a href=""{0}"">{0}</a></html>";
 
    public GridLinkCellElement(GridViewColumn column, GridRowElement row)
        : base(column, row)
    {
 
    }
 
    protected override string ApplyFormatString(object value)
    {
        return String.Format(LinkTemplate, value);
    }
}

Also, you need to set DisableHTMLRendering property of the column to false to enable the HTML-like feature. I recommend setting column's property ReadOnly to true:
this.radGridView.Columns["WebSite"].DisableHTMLRendering = false;
this.radGridView.Columns["WebSite"].ReadOnly = true;

Let us know if you need further assistance.

All the best,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Elver Emilio Cano Cardona
Top achievements
Rank 1
answered on 02 Jun 2010, 04:00 PM
Thanks a lot.. its works correctly..
regards..and thanks..
0
Robert
Top achievements
Rank 1
answered on 22 Mar 2011, 02:43 PM
I've been using this solution with some success, but I've had some problems when applying it to hierarchical grids.  In my application I have one column set up with GridLinkCellElements, but when I expand and contact the nested grids, the link-style formatting is incorrectly applied to other columns as well in a seemingly random way.  Is there any way to use this solution with hierarchical grids?
0
Svett
Telerik team
answered on 25 Mar 2011, 12:15 PM
Hi Robert,

I would kindly ask you to open support ticket, where you can enclose a sample project that demonstrates your scenario. This will help us to understand your case in depth.

Best wishes,
Svett
the Telerik team
Tags
GridView
Asked by
Elver Emilio Cano Cardona
Top achievements
Rank 1
Answers by
Svett
Telerik team
Elver Emilio Cano Cardona
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Share this question
or