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

RowSelected back color on Hyperlink click inside radGrid columns

1 Answer 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 23 Feb 2012, 06:31 PM
Row is not selected (background color) when i click on  Hyperlink inside a radGrid row.
pls refer to the sample code how i declared the Hyperlink inside RadGrid Columns.
I'm not using any <EditItemStyle....>

Lets say,
I have 5 rows in a RadGrid with a hyperlink in one column .
>i clicked on Row2 (not on the Hyper link) ...Row2 is Highlighted with default backcolor.
> now if i click on Hyperlink in Row3, the selected Row is still the Row2 with the highlighted backcolor.

So pls help me in fixing this.
...             
<Columns>
            <telerik:GridTemplateColumn AllowFiltering="false" Display="true" UniqueName="Edit" >                    
                        <ItemTemplate>                      
                                    <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server" >                           
                                            <a  href="<%= test %>" >
                                                 <img id="imgEdit" align="middle" style="border:0" alt="" src="edit.gif" />
                                         </a>                          
                                 </telerik:RadCodeBlock>                       
                        </ItemTemplate>                         
                     <HeaderStyle Width="30px" />
                      <ItemStyle HorizontalAlign="Left" />                       
             </telerik:GridTemplateColumn>
     ............
</Columns>
 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Oct 2012, 06:21 AM
Hi Robert,

I guess you are using GridHyperLinkColumn inside the RadGrid. Please check the following code snippet I tried to select a row on HyperLinkColumn click.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item1 = (GridDataItem)e.Item;
        HyperLink hyplnk = (HyperLink)item1["UniqueName"].Controls[0];
        hyplnk.Attributes.Add("OnClick", "return Click('" + item1.ItemIndex + "');");
    }
}

Javascript:
<script type="text/javascript">  
    function Click(indx)
    {
        var RadGrid2 = $find("<%= RadGrid1.ClientID %>");
         var gridSelectedItems = RadGrid2.get_masterTableView().get_selectedItems();
         for (var i = 0; i < gridSelectedItems.length; i++) {
             if (gridSelectedItems[i].get_selected()) {
                 gridSelectedItems[i].set_selected(false);
             }
         }     
        RadGrid2.get_masterTableView().get_dataItems()[indx].set_selected("true");
    }
</script>

Thanks,
Shinu.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or