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

Client side binding a hyperlink

3 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 23 Jul 2013, 01:52 PM
I have a page that contains a RadGrid.  One of the columns contains a hyperlink in an edit template as so:

    <telerik:GridTemplateColumn HeaderText="Asset Name" FilterControlAltText="FilterAssetName">
        <ItemTemplate>
            <asp:HyperLink ID="hplEditAsset" runat="server" ForeColor="Blue" AutoPostBackOnFilter="true"></asp:HyperLink>
        </ItemTemplate>
    </telerik:GridTemplateColumn>

I'm loading the data through a webservice, so I'd like to bind data to the grid on the client side. I'm trying to access the hyperlink in a javascript function as follows:

    function gridRowBound(sender, args) {
       var row = args.get_item()
       var link = $telerik.findElement(row , 'hplEditAsset');
       var d = args.get_dataItem();

       link.innerHtml = d.Url;
       link.outerHtml = d.UrlDescription; 
    } 

The data being bound to the grid is in the form of List<MyDataRow>, and MyDataRow has properties named Url and UrlDescription.

When I run the code, row is set to "tr#ctl00_MainContent_QuickScanGrid_ctl00__0.rgRow" according to Firebug. However, the script fails on the next line and link is never set.

How do I access that element so that I can bind the hyperlink to the data on the client side?

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 24 Jul 2013, 08:53 AM
Hello,

Please try with the below code snippet.
function RowDataBound(sender, args) {
    if (args.get_item().findElement("hplEditAsset")) {
                        var hplEditAsset = args.get_item().findElement("hplEditAsset");
         }
}

If above code is not working then please try with the below link.

Access RadGrid on client

Thanks,
Jayesh Goyani
0
Steven
Top achievements
Rank 1
answered on 24 Jul 2013, 11:49 AM
find_Element never returns true. I've tried various things (changing hyperlink to linkbutton, nameing the control the same as the datafield, But for some reason, it never seems to find that element.

Guess I'm going to have to try to reproduce it in a same program.
0
Steven
Top achievements
Rank 1
answered on 24 Jul 2013, 12:35 PM
Got excellent support help from Telerik on this. They had two alternative solutions:

1) A different type of callto findElement

function rowDataBound(sender, args) {
    var row = args.get_item();
    var d = args.get_dataItem();
    var link = $telerik.findElement(row.get_element()'hplEditAsset');
 
    $(link).text(d.ProductName);
}


2)  Instead of a GridItemTemplate, use a GridHyperLinkColumn, which is designed to bind automatically exactly how I wanted it.

I chose the second way and it worked on the first try. I never tried the first method.

Overall, I have to say Telerik support for is excellent. Don't always get it right first time, but they stick with you, sometimes even after you determine the problem is not their control.

Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Steven
Top achievements
Rank 1
Share this question
or