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

[Solved] Heirarchical Grid: How to Populate a FormTemplate Label in DetailTable from column values from MasterTableView

1 Answer 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 26 Sep 2009, 04:57 AM

Folks,

I have a   Heirarchical Grid (MasterTableView  and  DetailTables both uses FormTemplate). Is it possible while I am in DetailTable Edit/Insert mode, populate a label named (MasterTableUserFullName) in DetailTable with the Last+FirstName column values from MasterTableView?

In my RadGrid1_ItemDatabound event, I am able to populate that label (MasterTableUserFullName) with a string “Hellow World” but unsucessful to populate it with MasterTableView Last+FirstName Values.

Below is my code. Any help will be appreciated.

Thanks

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

        {

 

            if ((e.Item is GridEditableItem && e.Item.IsInEditMode))

            {

                GridDataItem parentItem = e.Item.OwnerTableView.ParentItem as GridDataItem;

                if (parentItem != null)

                {

                    GridEditableItem item = (GridEditableItem)e.Item;

 

                                     

                    Label txt = (Label)item.FindControl("MasterTableUserFullName");

 

                    txt.Text =  "Hellow World"; // This Works ...

                                      // but need to update the label Box with MasterTableView Last + First Name Values.

                   

                }

 

            }

      }

 

 _____________________________

 

<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomatic Inserts/Deletes/Updatess ="True" onitemdatabound="RadGrid1_ItemDataBound">           

      

<MasterTableView datakeynames="UserTablePrimaryKey" datasourceid="SqlDataSource1"  AllowFilteringByColumn = "true" CommandItemDisplay="TopAndBottom">

   

<!—Beginning Block of Child DetailTable -->

<DetailTables>

        <telerik:GridTableView runat="server" DataSourceID="SqlDataSource2" DataKeyNames="UserLocationsPrimaryKey"

                Width="100%"  CommandItemDisplay= "TopAndBottom" Name = "Detail" AllowAutomatic Inserts/Deletes/Updates ="True">

                <ParentTableRelation>

                <telerik:GridRelationFields DetailKeyField="UserTableForeignKey" MasterKeyField="UserTablePrimaryKey" /> </ParentTableRelation>

                

 <Columns>

        <telerik:GridBoundColumn DataField="UserTableForeignKey" 

            DataType="System.Int32" HeaderText="UserTableForeignKey"

            SortExpression="UserTableForeignKey" UniqueName="UserTableForeignKey"

                    Display="False" ReadOnly="True" Visible="False">

        </telerik:GridBoundColumn>

        <telerik:GridBoundColumn DataField="Program" HeaderText="Program" HeaderStyle-Width="50%"

            SortExpression="Program" UniqueName="Program" >

<HeaderStyle Width="50%"></HeaderStyle>

        </telerik:GridBoundColumn>

             .

             .

             .

 

    </Columns>

   

   <EditFormSettings EditFormType="Template">

<EditColumn UniqueName="EditCommandColumn1"></EditColumn>

    <FormTemplate>

    <table id="Table1" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"

                            style="border-collapse: collapse; background: white;">

                            <tr>

                                <td colspan="2" style="font-size:small;  z-index:0;  font-family:Bookman Old Style; color:#669999">

                                <asp:Label ID="MasterTableUserFullName"  runat="server" Text="User Location" Font-Underline="True"> 

               </asp:Label> 

                                  </td>

                            </tr>

             .

             .

             .

                     

   </table>

   

    </FormTemplate>

    </EditFormSettings>

   

        </telerik:GridTableView>

       

    </DetailTables>

 

<!—Ending Block of Child DetailTable -->

 

<!—Beginning Block of MasterTableView -->

 

    <Columns>

        <telerik:GridBoundColumn DataField="UserTablePrimaryKey"

            DataType="System.Int32" HeaderText="UserTablePrimaryKey" ReadOnly="True"

            SortExpression="UserTablePrimaryKey" UniqueName="UserTablePrimaryKey"

            Visible="False">

        </telerik:GridBoundColumn>

       

        <telerik:GridBoundColumn DataField="Last_Name" HeaderText="Last Name"

            SortExpression="Last_Name" UniqueName="Last_Name">

            <HeaderStyle Width="18%" />

            <ItemStyle Width="18%" />

        </telerik:GridBoundColumn>

        <telerik:GridBoundColumn DataField="First_Name" HeaderText="First Name"

            SortExpression="First_Name" UniqueName="First_Name">

            <HeaderStyle Width="18%" />

            <ItemStyle Width="18%" />

        </telerik:GridBoundColumn>

             

    </Columns>

    <EditFormSettings EditFormType="Template">

    <FormTemplate>

   

    <table id="Table2">

                                       

       <tr>

         <td>

           Last Name</td>

         <td>

          <asp:TextBox ID="TxtLast_Name" runat="server" Text='<%# Bind( "Last_Name") %>' TabIndex="1"> </asp:TextBox>

                                       

         </td>

                                                

         <td>

         First Name</td>

         <td>

         <asp:TextBox ID="TxtFirst_Name" runat="server" Text='<%# Bind( "First_Name") %>' TabIndex="2"> </asp:TextBox>

         </td>

                    

     </tr>

             .

             .

             .

 

   </table>

   

    </FormTemplate>

    </EditFormSettings>

    .

           .

    .

</MasterTableView>

 

<!— Ending Block  of MasterTableView -->

       

</telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 26 Sep 2009, 03:07 PM
Hello Ghulam,

In your case you can set the text of the label like this:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditableItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "Detail")) 
        { 
            GridEditableItem item = e.Item as GridEditableItem; 
            GridDataItem parentItem = item.OwnerTableView.ParentItem as GridDataItem; 
            if (parentItem != null
            { 
                Label txt = (Label)item.FindControl("MasterTableUserFullName"); 
                txt.Text = parentItem["Last_Name"].Text + " " + parentItem["First_Name"].Text; 
            } 
        } 
    } 

I hope this helps.

Regards,
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or