Hyperlink and DynamicHyperlink Column launch JavaScript

3 posts, 0 answers
  1. Gabriel
    Gabriel avatar
    18 posts
    Member since:
    Jun 2011

    Posted 08 Sep 2011 Link to this post

    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. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 15 Sep 2011 Link to this post

    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 >>

  3. Marcel
    Marcel avatar
    25 posts
    Member since:
    Jan 2011

    Posted 12 Dec 2012 Link to this post

    Is there an example on how to call a javascript function from the CellTemplate / Hyperlink button?

    Thank you
Back to Top