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

selectitem row when click on GridHyperLinkColumn or GridTemplateColumn

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lenny_shp
Top achievements
Rank 2
Lenny_shp asked on 20 Jan 2010, 07:31 PM
2009.3.1210.35
Requirement:  When GridHyperLinkColumn is clicked, I want the row to be selected.
I have  <Selecting AllowRowSelect="true" /> already but that doesn't select row when the link in HyperLinkColumn is clicked.
I can't add OnClick to GridHyperLinkColumn so I made a GridTemplateColumn and used <asp:hyperlink> instead which I could call a javascript with onClick.    However I do not know how to pass the current row index to the Row_Select function that I got from another post.

ClientEvent OnRowClick="RowClick" doesn't fire when clicked on the hyperlink either.

        <telerik:RadScriptBlock  runat="server"
            <script language="javascript" type="text/javascript"
                function Row_Select(arg) {   
                  var mt = $find("<%# RadGrid1.ClientID %>").get_masterTableView();   
                  var row = mt.get_dataItems()[arg];   
                  mt.selectItem(row.get_element()); 
              } 
 
              function RowClick(sender, eventArgs) { 
                  var mt = $find("<%# RadGrid1.ClientID %>").get_masterTableView(); 
                  var row = mt.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; 
                  mt.selectItem(row.get_element()); 
              } 
            </script> 
        </telerik:RadScriptBlock > 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 21 Jan 2010, 06:02 AM
Hello Lenny,

You can pass the index from code behind in the ItemDataBound event as shown below.

Code behind:
 
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            HyperLink hLink = (HyperLink)item.FindControl("HyperLink1"); 
            hLink.NavigateUrl = "#"
            hLink.Attributes.Add("onclick""selectMe('"+item.ItemIndex+"');"); 
        } 
    } 

And in the client side:
 
    function selectMe(index) { 
        alert(index); 
        var mt = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
        var row = mt.get_dataItems()[index]; 
        row.set_selected(true); 
    } 

-Shinu.
Tags
Grid
Asked by
Lenny_shp
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 1
Share this question
or