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

Hierarchical grid

1 Answer 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dilip
Top achievements
Rank 1
Dilip asked on 21 Nov 2008, 05:38 AM
I have a Hierarchical grid. with ShoppingCenter as master table and Shop as a details

SHopping Center : Id, Name
Shop : Id, ShoppingCenterId, Name

When I am trying to insert a child record i am not getting the parent id. here is my declaration


  <telerik1:RadGrid ID="RadGrid1" runat="server" Skin="Web20"
                        GridLines="None" AllowPaging="True" AllowSorting="True"
        Width="97%" AutoGenerateColumns="False"
                        ShowStatusBar="True"
        OnNeedDataSource="RadGrid1_NeedDataSource"
        OnUpdateCommand="RadGrid1_UpdateCommand" 
        OnInsertCommand="RadGrid1_InsertCommand"
        onitemcreated="RadGrid1_ItemCreated"
        OnDeleteCommand="RadGrid1_DeleteCommand" OnDetailTableDataBind="RadGrid1_DetailTableDataBind">
  

<MasterTableView GridLines="None" Width="100%" CommandItemDisplay="Top"
   DataKeyNames="Id" AllowAutomaticInserts="True">
                             <CommandItemTemplate>
                    <div style="padding: 0 5px;">
                        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert"
                        Visible ='<%# !RadGrid1.MasterTableView.IsItemInserted %>'>
                        Add Item</asp:LinkButton>
                    </div>
                </CommandItemTemplate>
<detailtables>
   <telerik1:GridTableView runat="server" DataKeyNames="Id"  Name="SCCotenants" AllowAutomaticDeletes="true" AllowAutomaticInserts="true"
          AllowAutomaticUpdates="true" CommandItemDisplay="Top">
      <CommandItemTemplate>
                    <div style="padding: 0 5px;">
                        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert"
                        Visible ='<%# !RadGrid1.MasterTableView.IsItemInserted %>'>
                        Add Cotenant</asp:LinkButton>
                    </div>
                </CommandItemTemplate>
 <parenttablerelation>
        <telerik1:GridRelationFields DetailKeyField="ShoppingCenterId" MasterKeyField="Id" />
                                    </parenttablerelation>
                                    <rowindicatorcolumn>
                                        <HeaderStyle Width="20px" />
                                    </rowindicatorcolumn>
                                    <expandcollapsecolumn>
                                        <HeaderStyle Width="20px" />
                                    </expandcollapsecolumn>
    <Columns>
                                 
     <telerik1:GridBoundColumn DataField="ShoppingCenterId"
                                            HeaderText="Shopping Center" UniqueName="ShoppingCenterIDColumn" Visible="true" ItemStyle-Wrap="True">
                                        </telerik1:GridBoundColumn>

 



and in the  insertcommand 

var scid = (e.Item as GridEditableItem)["ShoppingCenterIDColumn"].Controls[0] as TextBox;
 scct.ShoppingCenterId = int.Parse(((TextBox)scid).Text);


i am not getting the ParentId here. Not sure what I am missing. Can someone help me with this one please.


Thanks
Dilip

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Nov 2008, 07:17 AM
Hi Dilip,

Here ia a help article which explains how to access the parent item in a hierarchical grid on doing Update/Insert. Go through it and see if it helps.
Extracting primary key value for parent item in hierarchy on Update/Insert

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