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

How to bind NestedViewTemplate within a RadGrid from Code behind using a datasource

2 Answers 521 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jahanzaib
Top achievements
Rank 1
Jahanzaib asked on 14 Feb 2014, 05:14 PM
Hi,

i am new to Telerik controls. i am in a situation where i need to bind a NestedViewTemplate  with a datasource having values from different tables connected with an id of an item within a RadGrid.
what i want to do is to bind that nested view template by getting value of id from its RadGrid using a datasource.
i have tried many option but didnt find any luck. is there anyway to bind its datasource from code behind as we do with RadGrid (as radgrid.datasource="any datasource").
is there any way to do that

<asp:EntityDataSource ID="EDSPrePostConfig" runat="server" ConnectionString="name=AdminPortalDBEntities"
                            DefaultContainerName="AdminPortalDBEntities" EntitySetName="PrePostConfigurations"
                            Select="PrePostCourseActivities.[CourseName] as PreLearning,
                            PrePostConfiguration.[Duration] as Duration
                             from (PrePostConfiguration
                            join LearningMatrix on PrePostConfiguration.[BaseCourseId]  = LearningMatrix.[Id]
                            join PrePostCourseActivities on PrePostConfiguration.[PrePostCourseActivityId] = PrePostCourseActivities.[Id]
                            join PrePostType on PrePostConfiguration.[PrePostTypeId] = PrePostType.[Id])" Where="PrePostConfigurations.[Id] = @Id">
                        <WhereParameters>
                             <asp:Parameter Name="Id" Type="Int32"/>
                        </WhereParameters>
                   
                </asp:EntityDataSource>

<NestedViewSettings  DataSourceID="EDSPrePostConfig">
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="Id" MasterKeyField="Id" />
                            </ParentTableRelation>
                        </NestedViewSettings>
                        <NestedViewTemplate>
                            <asp:Panel ID="NestedViewPanel" runat="server" CssClass="viewWrap" BorderColor="#3366FF" BorderWidth="3px">
                                <div class="contactWrap">
                                    <table width="90%">
                                        <tbody>
                                            <tr>
                                                <td><b>Pre-Learning Configurations:</b> </td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td width="100">Pre-Learning: </td>
                                                <td><%#Eval("PreLearning") %></td>
                                                <td width="100">Duration: </td>
                                                <td><%#Eval("Duration") %></td>
                                            </tr>
                                            <tr>
                                                <td>Required: </td>
                                                <td><%#Eval("Required") %></td>
                                                <td>Feedback URL: </td>
                                                <td><%#Eval("PreFeedbackURL") %></td>
                                            </tr>
                                        
                                          
                                        </tbody>
                                    </table>
                                </div>
                            </asp:Panel>
                        </NestedViewTemplate>

it would be great if someone can help me with this.

Thanks and BR
JK

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 15 Feb 2014, 07:03 AM
Hi Jahanzaib,

I guess you are trying to bind a radgrid in the NestedViewTemplate and you want to access the parent Radgrid id to set its datasource. Please have look into the following code snippet to access the parent DataKeyValue in the NeedDataSource event of the NestedRadGrid:

C#:
protected void RadGrid2_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
 GridDataItem parentItem = ((sender as RadGrid).NamingContainer as GridNestedViewItem).ParentItem as GridDataItem;
 string id=parentItem.GetDataKeyValue("ID").ToString();
 (sender as RadGrid).DataSource = "Your datasource";
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
 if (e.CommandName == RadGrid.ExpandCollapseCommandName && !e.Item.Expanded)
  {
   GridDataItem parentItem = e.Item as GridDataItem;
   RadGrid grid = parentItem.ChildItem.FindControl("RadGrid2") as RadGrid;
   grid.Rebind();
  }
}

Thanks,
Shinu
0
Jahanzaib
Top achievements
Rank 1
answered on 15 Feb 2014, 07:54 AM
Thanks alot Shinu.
that worked for me. 
Tags
Grid
Asked by
Jahanzaib
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jahanzaib
Top achievements
Rank 1
Share this question
or