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

Get Row client side from item template link button

1 Answer 284 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mahen
Top achievements
Rank 1
Mahen asked on 11 Oct 2012, 01:34 AM
Hi
I have a link button inside the GridTemplateColumn, and i want to know the row index when i click on the link button client side.
Below is the code i have:

<telerik:RadGrid ID="grdDetailSummary" runat="server">
         <MasterTableView DataKeyNames="Id" ClientDataKeyNames="Id">
                <Columns>
                     <telerik:GridTemplateColumn HeaderText="Open" UniqueName="colOpenLink">
                        <ItemTemplate>
                            <asp:LinkButton runat="server" ID="lnkReason" Font-Underline="true"  Text="Open" OnClientClick="javascript:OpenNewWindow()"></asp:LinkButton>
                        </ItemTemplate>
                     </telerik:GridTemplateColumn>
                </Columns>
        </MasterTableView>
    </telerik:RadGrid>
 
<script language="javascript" type="text/javascript">
        function OpenNewWindow() {
            //I want to know the row index here, and ultimately i want to get the value from datakeyvalues.
        }
        </script>

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Oct 2012, 03:19 AM
Hi,

Please try the following approach to get the row index in the Client side on a link button click.

ASPX:
<telerik:GridTemplateColumn HeaderText="Open" UniqueName="colOpenLink">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnkReason" Font-Underline="true"  Text="Open"></asp:LinkButton>
            </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadgRid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem ditem = (GridDataItem)e.Item;
        LinkButton lnk = (LinkButton)ditem.FindControl("lnkReason");
        lnk.Attributes.Add("OnClick", "OpenNewWindow('" + ditem.ItemIndex + "');");
    }
}

Javascript:
<script language="javascript" type="text/javascript">
    function OpenNewWindow(index)
    {
        alert(index);
    }
</script>

Hope this helps.

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