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

[Solved] RadGrid in EditTemplateForm

2 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 19 May 2009, 08:10 PM
I have a grid with a single master table view, which has an Form Template declared.  The form template contains (among other things) another RadGrid which needs to have it's NeedDataSource event wire up a data source.

<RadGrid

 

ID="m_rgMain" runat="server" Width="100%" AllowFilteringByColumn="false" OnNeedDataSource="m_rgMain_NeedDataSource"

 

 

OnItemCommand="m_rgMain_ItemCommand" OnItemDataBound="m_rgMain_ItemDataBound" >

 

 

<MasterTableView DataKeyNames="WmTaskId" HierarchyDefaultExpanded="true">

 

 

<Columns>

 

 

<telerik:GridButtonColumn UniqueName="EditButton" ButtonType="ImageButton" CommandName="Edit"

 

 

Text="View / Edit Task" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20px">

 

 

</telerik:GridButtonColumn>

 

 

<telerik:GridButtonColumn UniqueName="ViewButton" ButtonType="ImageButton" ImageUrl="View.png"

 

 

CommandName="View" Text="View Entity" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="20px" />

 

 

<telerik:GridBoundColumn SortExpression="WmTaskId" HeaderText="Id"

 

 

HeaderButtonType="TextButton" DataField="WmTaskId" AllowFiltering="false">

 

 

<ItemStyle Width="50" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn SortExpression="PrioritySequence" HeaderText="Priority" HeaderButtonType="TextButton"

 

 

DataField="PrioritySequence" >

 

 

<ItemStyle Width="50" />

 

 

</telerik:GridBoundColumn>

 

 

    . . . other columns here
</
Columns>

 

 

<EditFormSettings EditFormType="Template">

 

 

<FormTemplate>

 

 

<table class="FormTable" width="100%" border="0" cellpadding="0" cellspacing="0">

 

 

<tr valign="top">

 

 

<td class="FormLabelCell">

 

 

<tst:TstLiteral runat="server" ID="litRole" Text="Role:"></tst:TstLiteral><br />

 

 

<tst:TstLabel runat="server" ID="lblRole"></tst:TstLabel>

 

 

</td>

 

 

 

</tr>

 

 

<tr>

 

 

<td class="FormFooterCell" colspan="7">

 

 

<RadGrid ID="rgCompany" runat="server" Width="99%" ShowStatusBar="true"

 

 

AutoGenerateColumns="False" AllowMultiRowSelection="False"

 

 

GridLines="None" OnNeedDataSource="rgCompany_NeedDataSource">

 

 

<MasterTableView Width="100%" DataKeyNames="CompanyId" AllowMultiColumnSorting="True">

 

 

<Columns>

 

 

<telerik:GridBoundColumn HeaderText="ID" HeaderButtonType="TextButton"

 

 

DataField="CompanyId">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn HeaderText="Name" HeaderButtonType="TextButton"

 

 

DataField="CompanyShortName">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn HeaderText="Phone" HeaderButtonType="TextButton"

 

 

DataField="CompanyPhoneNumber">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

</RadGrid>

 

 

</td>

 

 

</tr>

 

 

</table>

 

 

</FormTemplate>

 

 

</EditFormSettings>

 

 

</MasterTableView>

 

</Rad

 

Grid>
In the edit form template, I want to show the companies associated with my taskId as information to the user editing the task info.
I can can get the EditFormTempalte at ItemDataBound time, then get the company RadGrid using FindControl and call its Rebind().
However, in the rgCompany.NeedDataSource event (which does fire), I can't get back to :
A)  the parent grid to get the key for which to drive my look up of the associated company data and
B)  I can't get a reference to the rgCompany grid so as to set the datasource to my company result set.

Is this possible and if so, can you provide the details of how to do it?

Thanks.

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 20 May 2009, 05:09 AM
Hello Mark,

You can try out the following code to access the parent grid in the NeedDataSource event of the nested grid:
c#:
protected void rgCompany_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        RadGrid rgCompanyGrid = (RadGrid)source; // to access the nested grid 
        GridEditFormItem editFormItem = (GridEditFormItem)rgCompanyGrid.NamingContainer;// access the container of the nested grid 
        GridDataItem dataItem = (GridDataItem)editFormItem.ParentItem; // to get the parent item of the parent grid 
        string taskId = dataItem.GetDataKeyValue("WmTaskId").ToString(); 
 
        rgCompanyGrid.DataSource = ds//set DataSource for the nested grid here 
         
    } 

Thanks
Princy.
0
Mark
Top achievements
Rank 1
answered on 21 May 2009, 04:46 PM
Thanks!
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Share this question
or