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

Hierarchical Grid Custom CommandItemDisplay

3 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 20 Aug 2009, 10:36 PM
Hello all.  I have a RadGrid with 1 MasterTableView and 1 GridTableView.  I want to implement
a custom CommandItemDisplay that opens a new window for adding the record.  My only
problem is that I will need to send the "ID" of the parent grid item.  Obviously this will be done
through JavaScript, however, I don't know how to get the required data I need to send the
Add Record Window.

I have a link button in the GTV CommandItemDisplay that runs the JS Code below right now.

   function Add(sender, args) {  
       // var eventid = args.get_parent.get_dataKeyValue("ID");
       alert("Add record for master # " + eventid);  
   } 

Anyone have any ideas?  Thanks in advance.

Joshua

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 Aug 2009, 09:55 AM
Hi Josh,

I suppose you are trying pass the Key value of the Parent table row on clicking the the control in the CommandItemTemplate of a Detail table. If so give a try with the following approach and see whether it helps.

ASPX:
 
          <DetailTables> 
                    <telerik:GridTableView DataKeyNames="OrderID" Name="Detail" CommandItemDisplay="top" DataSourceID="SqlDataSource2" Width="100%" 
                        runat="server"
                        <CommandItemTemplate> 
                            <asp:LinkButton ID="AddNewBtn" runat="server">LinkButton</asp:LinkButton> 
                        </CommandItemTemplate> 
            ....... 


CS:
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if((e.Item is GridCommandItem)&&(e.Item.OwnerTableView.Name=="Detail")) 
        { 
            GridCommandItem cmdItm = (GridCommandItem)e.Item; 
            string ID = cmdItm.OwnerTableView.ParentItem.GetDataKeyValue("EmployeeID").ToString(); 
            LinkButton lnkBtn = (LinkButton)cmdItm.FindControl("AddNewBtn"); 
            lnkBtn.Attributes.Add("OnClick","return Add('"+ ID+"');"); 
        } 
    } 

JS:
 
<script type="text/javascript" > 
 function Add(ID) 
 { 
  alert(ID) 
 } 
</script> 


Regards
Princy.
0
Josh
Top achievements
Rank 1
answered on 21 Aug 2009, 01:33 PM
You have come through again.  Thanks Princy.
0
Princy
Top achievements
Rank 2
answered on 24 Aug 2009, 05:22 AM
Hi Josh,

You may also go through the following help article which shows how to extract primary key value for parent item in hierarchical Grid.
Extracting primary key value for parent item in hierarchy on Update/Insert

Princy
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Josh
Top achievements
Rank 1
Share this question
or