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

[Solved] Getting data from mastertableview in gridtableview

2 Answers 337 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Janak
Top achievements
Rank 1
Janak asked on 29 May 2013, 09:35 PM
I have a table like this

<mastertableview datakeynames = "someid, otherid, ...">
<detailtables>
<gridtableview>
<detailtables>
<gridtableview>
<columns>
<gridtemplatecolumn>
<itemtemplate>
<a onClick = 'somejavascriptfunction( I need the value of someid from mastertableview here (how do i do it?)'> Text </a>
</itemtemplate>
</gridtemplatecolumn>
</column>
</gridtableview>
</detailtables>
</gridtableview>
</detailtables>
</masterview>

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 May 2013, 01:18 PM
Hi Janak,

Please try the following code snippet to get the MasterTable's  DataKeyValue in DetailTable anchor click.

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "DeatilTableName")
    {
        GridDataItem ditem = (GridDataItem)e.Item;
        GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem;
        string data = parentItem.GetDataKeyValue("SomeID").ToString();
        HtmlAnchor an = (HtmlAnchor)ditem.FindControl("Anchor1");
        an.Attributes.Add("OnClick", "somejavascriptfunction('" + data + "')");
    }
}

Javawscript:
<script type="text/javascript">
    function somejavascriptfunction(dataKey) {
        alert(dataKey);
    }
</script>

Thanks,
Princy.

0
Janak
Top achievements
Rank 1
answered on 30 May 2013, 02:49 PM
Thanks Princy. Worked.
Tags
Grid
Asked by
Janak
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Janak
Top achievements
Rank 1
Share this question
or