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

Hyperlink and DynamicHyperlink Column launch JavaScript

2 Answers 76 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gabriel
Top achievements
Rank 1
Gabriel asked on 08 Sep 2011, 08:22 PM

What is the simplest way to call a javascript funcrtion from a GridViewHyperlinkColumn or a GridViewDynamicHyperlinkColumn (directly or with code behind?

For now, I've created a custom column with an HyperlinkButton, but the UI rendering is not the same as the 2 out of  the box columns. What I would like to see is a Command implementation with parameters, similar to the GridViewDynamicHyperlinkColumn's NavigateUrlFormatString and NavigateUrlMemberPaths property.
   

public class GridViewItemLinkColumn : GridViewDynamicHyperlinkColumn
{
    public override FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
    {
        this.BindingTarget = HyperlinkButton.ContentProperty;
        HyperlinkButton btn = new HyperlinkButton();
        btn.Click += new RoutedEventHandler(btn_Click);
        btn.SetBinding(this.BindingTarget, this.CreateValueBinding());
 
        return btn;
    }
 
    void btn_Click(object sender, RoutedEventArgs e)
    {
        string str = this.DataControl.Items.IndexOf(((HyperlinkButton)sender).DataContext).ToString();
    }
    private Binding CreateValueBinding()
    {
        Binding valueBinding = new Binding();
        valueBinding.Mode = BindingMode.TwoWay;
        valueBinding.NotifyOnValidationError = true;
        valueBinding.ValidatesOnExceptions = true;
        valueBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
        valueBinding.Path = new PropertyPath(this.DataMemberBinding.Path.Path);
 
        return valueBinding;
    }
}

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 Sep 2011, 07:08 AM
Hello,

 You can use also CellTemplate of GridViewDataColumn to declare desired HyperlinkButton. 

Best wishes,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Marcel
Top achievements
Rank 1
answered on 12 Dec 2012, 07:10 PM
Is there an example on how to call a javascript function from the CellTemplate / Hyperlink button?

Thank you
Tags
GridView
Asked by
Gabriel
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Marcel
Top achievements
Rank 1
Share this question
or