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

OnSelectedIndexChanged fires when OnSelectedIndexChanged clicked

2 Answers 100 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Big asked on 16 May 2012, 03:10 PM
sorry, the title is incorrect  

OnSelectedIndexChanged fires when 

GridHyperLinkColumn is clicked! 

I have a RadGrid that uses the OnSelectedIndexChanged (which fires off some other events that changes things on the screen)

The first column in this RadGrid is a GridHyperLinkColumn which uses DataNavigateUrlFormatStringWhen a user clicks the GridHyperLinkColumn  we want the OnSelectedIndexChanged  

<telerik:RadGrid runat="server" Height="150"  ID="grdData" EnableEmbeddedSkins="false" OnSelectedIndexChanged="grdData_SelectedIndexChange" OnPreRender="grdData_PreRender"
Skin="AS_Grid_Skin_V10" AutoGenerateColumns="False" AllowPaging="False" AllowSorting="True" Width="100%" OnItemDataBound="grdData_ItemDataBound">
                            <ClientSettings EnablePostBackOnRowClick="true">
                                <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="false" />
                                <Selecting AllowRowSelect="true" />
                            <MasterTableView DataKeyNames="ID">
                                    <telerik:GridHyperLinkColumn  HeaderText="<%$ Resources:GlobalTerms, lblName%>"                        DataTextField="Name"
                                                                  DataNavigateUrlFields="Id" DataNavigateUrlFormatString="javascript:openScenarioDashboard('{0}');"
                                                                  UniqueName="Name" SortExpression="Name"/>

So in the end, the user clicks the GridHyperLinkColumn link and we want to simulate the 

 protected void grdData_SelectedIndexChange(object sender, EventArgs e)

//runs some code here when the Row is clicked, not the link.  We want both

any ideas?

2 Answers, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 16 May 2012, 04:47 PM
any ideas on this ?

When we use the OnSelectedIndexChanged property of the RadGrid the user can click the row and it fires the "grdData_SelectedIndexChange" which does some updates.

Within that same grdData Grid, the first column is a GridHyperLinkColumn which uses DataNavigateUrlFormatString to call some javascript to open up a page.

When the user clicks the GridyperLinkColumn link, we would like the OnSelectedIndexChanged to fire just as if the user clicked the row.

Sorry for repeating, but maybe its clearer now.

Any ideas?

Top achievements
Rank 1
answered on 18 May 2012, 09:14 PM

You can use the following approach to attach an "onclick" event to the Hyperlink in your GridHyperLinkColumn which can then be used to fire a client-side JavaScript function that selects the row in which that Hyperlink is embedded. This should, then, kick off the RadGrid SelectionChangedEvent.

The redirect using the DataNavigateUrlFormatString still occurs.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<head runat="server">
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    <script type="text/javascript">
        function selectThisRow(index) {
            var mt = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
            var row = mt.get_dataItems()[index];
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AllowPaging="True" ShowFooter="True"
            runat="server" AutoGenerateColumns="False" AllowSorting="True"
            PageSize="3" GridLines="None"
            CellPadding="0" AllowMultiRowSelection="True" CellSpacing="0"
            <mastertableview showfooter="True">
                    <telerik:GridClientSelectColumn UniqueName="CheckboxSelectColumn" FooterText="CheckBoxSelect footer" />
                    <telerik:GridBoundColumn FooterText="BoundColumn footer" UniqueName="CompanyName"
                        SortExpression="CompanyName" HeaderText="Company Name" DataField="CompanyName">
                     <telerik:GridHyperLinkColumn FooterText="HyperLinkColumn footer" DataTextFormatString="Search Google for '{0}'"
                        DataNavigateUrlFields="CompanyName" UniqueName="CompanyLink" DataNavigateUrlFormatString=";q={0}&btnG=Google+Search"
                        HeaderText="HyperLink<br/>Column" DataTextField="CompanyName">
                <Selecting AllowRowSelect="true" />
    <asp:SqlDataSource ID="SqlDataSource1"
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM [Customers]"

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
public partial class Default : System.Web.UI.Page
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        if (e.Item is GridDataItem)
            GridDataItem dataItem = e.Item as GridDataItem;
            HyperLink companyName = dataItem["CompanyLink"].Controls[0] as HyperLink;
            companyName.Attributes.Add("onclick", "selectThisRow('" + dataItem.ItemIndex + "');");
    protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
        // run the code that you need here

Hope this helps!

Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Top achievements
Rank 1
Share this question