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

Need to add a Detail table in the existing grid

3 Answers 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joselina
Top achievements
Rank 1
Joselina asked on 06 Feb 2014, 10:07 PM
Hello,

I need to add detail table in the existing grid, the grid has only mastertableview currently. I am able to add the markup but i am not able to fully understand the code written in NeedsDataSource event. I tried to split the code to detailTable DataBind but it is passing the same DataKeyValueto all the records of the detail table. So please help me to do this. I have provided the grdfilesParent Design markup and the code in NeedDataSource Event. and also the STGrdNotesMaster grid design markup, like this i need to change the grdfilesParent . Help me to convert it.
Existing Grid With Only Master Table
-------------------------------------------
 
<ST:STGrid ID="grdfilesParent" runat="server" Width="100%" AllowPaging="false"
                                        GroupingEnabled="true" ShowGroupPanel="false"  EnableHierarchyExpandAll="true" >
                                        <MasterTableView  HierarchyLoadMode ="Client"  >
                                            <Columns>
                                                <tel:GridBoundColumn UniqueName="Name" DataField="Name" HeaderText="Category" />
                                                <tel:GridHyperLinkColumn UniqueName="Subject" DataTextField="Subject" HeaderText="Subject"
                                                    DataNavigateUrlFormatString="attachments/display.aspx?id={0}" DataNavigateUrlFields="ID"
                                                    SortExpression="Subject">
                                                    <ItemStyle CssClass="gridhyperlink" />
                                                </tel:GridHyperLinkColumn>
                                                <tel:GridHyperLinkColumn UniqueName="FileName" DataTextField="FileName" HeaderText="Attachment"
                                                    DataNavigateUrlFormatString="{0}" DataNavigateUrlFields="AttachmentUrl" SortExpression="FileName"
                                                    Target="_blank">
                                                    <ItemStyle CssClass="gridhyperlink" />
                                                </tel:GridHyperLinkColumn>
                                                <tel:GridDateTimeColumn UniqueName="CreatedDate" DataField="CreatedDate" HeaderText="Date" />
                                                <tel:GridBoundColumn UniqueName="CreatedBy" DataField="CreatedBy" HeaderText="Author" />
                                            </Columns>
                                            <GroupByExpressions>
                                                <tel:GridGroupByExpression>
                                                    <SelectFields>
                                                        <tel:GridGroupByField FieldName="Name" FieldAlias="Category"  />
                                                    </SelectFields>
                                                    <GroupByFields>
                                                        <tel:GridGroupByField FieldName="Name" />
                                                    </GroupByFields>
                                                </tel:GridGroupByExpression>
                                            </GroupByExpressions>
                                        </MasterTableView>
                                        <ClientSettings AllowExpandCollapse="true">
                                         </ClientSettings>
            </ST:STGrid>
---------------------------------------------------
NeedDataSource Event of Above Grid:
--------------------------------------------
Private Sub grdfilesParent_NeedsDataSource(ByVal sender As Object, ByVal e As GridNeedDataSourceEventArgs) Handles grdAttachmentsParent.NeedDataSource
        Dim types As fileTypeList = CurrentST.GetfileTypes()
        Dim attachments = types.Aggregate(
         New List(Of Object)(),
         Function(acc As List(Of Object), type As STfileType)
             Dim typefilements As STfilementList = Document.Getfilements(type.ID)
             typefilements.Aggregate(
              acc,
              Function(acc2 As List(Of Object), filement As STfile)
                  Dim extension = file.Extension.ToLower()
                  Dim navigationUrl As String = String.Empty
 
                  If CurrentSTClient.av Then
                      navigationUrl = String.Format("files/view.aspx?id={0}&path={1}&aid={2}", file.Document.ID, file.FileName, file.ID)
                  ElseIf EnableCommentsWithfiles Then
                      navigationUrl = String.Format("reviews/displayReadOnlyOptional.aspx?id={0}&type=file&path={1}&aid={2}", file.Document.ID, file.FileName, file.ID)
                  Else
                      If (extension = "docx" _
                       OrElse extension = "doc" _
                       OrElse extension = "dotx" _
                       OrElse extension = "dot" _
                       OrElse extension = "rtf" _
                       OrElse extension = "xls" _
                       OrElse extension = "xlsx" _
                      ) Then
                          navigationUrl = String.Format(
                           "reviews/displayreadonly.aspx?id={0}&type=file&path={1}",
                           file.ID,
                           file.FileName
                          )
                      Else
                          navigationUrl = file.VirtualPath
                      End If
                  End If
 
                  acc2.Add(New With {
                   Key .Name = type.Name,
                 .ID = file.ID,
                 .Subject = file.Subject,
                 .FileName = file.FileName,
                 .CreatedDate = String.Format("{0} {1}", file.CreatedDate.ToString(CurrentCulture.DateTimeFormat.ShortDatePattern, CurrentCulture), file.CreatedDate.ToString(CurrentCulture.DateTimeFormat.ShortTimePattern, CurrentCulture)),
                 .CreatedBy = file.CreatedBy,
                  .fileUrl = navigationUrl
                  })
                  Return acc2
              End Function
             )
             Return acc
         End Function
        )
 
 
        DirectCast(grdAttachmentsParent.Columns(1), GridHyperLinkColumn).DataNavigateUrlFormatString = String.Format("{0}cc/files/display.aspx?id={1}0{2}", Captions.VirtualRoot, Chr(123), Chr(125))
 
        grdfilesParent.DataSource = files.ToArray()
 
End Sub
---------------------------------------------
 
I need to convert the above grid to  the Grid like below with Master - Detail
-----------------------------------------------------------------------------------------
<ST:STGrid ID="STGrdNotesMaster" runat="server" TabIndex="212" AutoGenerateColumns="false" AllowSorting="false" AllowPaging="false" ClientSettings-AllowColumnsReorder="false" ClientSettings-AllowDragToGroup="false" ShowGroupPanel="false" EnableHierarchyExpandAll="true" MasterTableView-ExpandCollapseColumn-HeaderStyle-BackColor="LightGray" >
                                            <MasterTableView DataKeyNames="ID" HierarchyDefaultExpanded="false" NoMasterRecordsText="" NoDetailRecordsText="" GroupLoadMode="Client" HierarchyLoadMode ="Client" >
                                                <Columns>
                                                    <telerik:GridBoundColumn HeaderText="Category" DataField="Name" UniqueName="Category" />
                                                    <telerik:GridTemplateColumn UniqueName="Reorder">
                                                        <ItemTemplate><ST:STButton ID="btnReorder" runat="server" CommandName="reorder" Text="Reorder based on sort" /></ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                </Columns>
                                                <DetailTables>
                                                    <telerik:GridTableView Name="Detail" AllowSorting="true" AllowPaging="false" DataKeyNames="ID" NoMasterRecordsText="" NoDetailRecordsText="" EditMode="InPlace">
                                                        <Columns>
                                                            <telerik:GridHyperLinkColumn UniqueName="Subject" HeaderText="Subject" DataNavigateUrlFormatString="~/notedisplay.aspx?id={0}" DataNavigateUrlFields="ID" DataTextField="Subject" SortExpression="Subject" ItemStyle-CssClass="gridhyperlink" HeaderStyle-Width="500px" />
                                                            <telerik:GridHyperLinkColumn UniqueName="file" HeaderText="file" DataNavigateUrlFormatString="javascript:void(window.open('imageviewer.aspx?a=3&b=file&c={0}', '_blank', 'left=0, top=0, width=785, height=585, titlebar=yes, location=no, status=no, toolbar=no, menubar=no, scrollbars=no, resizable=yes'));" DataNavigateUrlFields="ID" DataTextField="fileName" SortExpression="fileName" ItemStyle-CssClass="gridhyperlink" />
                                                            <telerik:GridBoundColumn UniqueName="AddDate" HeaderText="Created" DataField="AddDate" SortExpression="AddDate" ReadOnly="true" />
                                                            <telerik:GridEditCommandColumn UniqueName="EditColumn">
                                                                <ItemStyle CssClass="gridhyperlink" />
                                                            </telerik:GridEditCommandColumn>
                                                        </Columns>
                                                    </telerik:GridTableView>
                                                </DetailTables>
                                            </MasterTableView>
                                            <ClientSettings AllowExpandCollapse="true">
                                            </ClientSettings>
                                        </ST:STGrid>

3 Answers, 1 is accepted

Sort by
0
Joselina
Top achievements
Rank 1
answered on 07 Feb 2014, 09:43 PM
Can anyone help me on this? 

Thanks
Joselina
0
Accepted
Kostadin
Telerik team
answered on 11 Feb 2014, 01:32 PM
Hello Joselina,

I would recommend you to examine the following help articles.
Hierarchical data-binding using declarative relations
Hierarchical data-binding using DetailTableDataBind event

You could examine the rest of the help topics for additional information.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Joselina
Top achievements
Rank 1
answered on 21 Feb 2014, 09:48 PM
I resolved it by debugging the code. Thanks for the reply.
Tags
Grid
Asked by
Joselina
Top achievements
Rank 1
Answers by
Joselina
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or