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

Grid has only MasterTableView and the bound column is binding with list of objects.Need to get the count of items in a bound column.

3 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joselina
Top achievements
Rank 1
Joselina asked on 20 Nov 2013, 07:18 PM
Hi ,

I need to show the count along with the name of the bound column.The grid has only master table view and the bound column is getting the values of a list.
ex:
Category:Doc1(2) 
Catgeory:Doc2(4)
Categroy:Doc3(5).....

I tried with Pre-render event but it is adding the count in the child items only. please help me to get the count of the values of the bound column.
Below
<ad:adGrid ID="grdAttachments" runat="server" Width="100%" AllowPaging="false"
    GroupingEnabled="true" ShowGroupPanel="false" MasterTableView-GroupsDefaultExpanded="true" >
        <MasterTableView  HierarchyLoadMode ="Client" >
        <Columns>
    <tel:GridBoundColumn UniqueName="Name" DataField="Name" HeaderText="Category" />
    <tel:GridHyperLinkColumn UniqueName="Subject" DataTextField="Subject" HeaderText="Subject"
    DataNavigateUrlFormatString="ts/disp.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>
</ad:adGrid>
----------------------------------------------------------------
 
 
 
 
Private Sub grdAttachments_NeedsDataSource(ByVal sender As Object, ByVal e As GridNeedDataSourceEventArgs) Handles grdAttachments.NeedDataSource
        Dim types As ADAttachmentTypeList = CMClient.GetAttacntTyps()
        Dim attachments = types.Aggregate(
         New List(Of Object)(),
         Function(acc As List(Of Object), type As ADAttachmentType)
             Dim typeAttachments As ADAttachmentList = Document.GetAttachments(type.ID)
             typeAttachments.Aggregate(
              acc,
              Function(acc2 As List(Of Object), attachment As ADAttachment)
                  Dim extension = attachment.Extension.ToLower()
                  Dim navigationUrl As String = String.Empty
 
                  If CurrentTADClient.CCV Then
                      navigationUrl = String.Format("ts/view.aspx?id={0}&path={1}&aid={2}", attachment.Document.ID, attachment.FileName, attachment.ID)
                  ElseIf EnableCommentsWithAttachments Then
                      navigationUrl = String.Format("reviews/dispyReadOnlyOpt.aspx?id={0}&type=ATTACHMENT&path={1}&aid={2}", attachment.Document.ID, attachment.FileName, attachment.ID)
                  Else
                      If (extension = "docx" _
                       OrElse extension = "doc" _
                       OrElse extension = "dotx" _
                       OrElse extension = "dot" _
                       OrElse extension = "rtf" _
                      ) Then
                          navigationUrl = String.Format(
                           "rev/dispyreadonly.aspx?id={0}&type=ATTACHMENT&path={1}",
                           attachment.Document.ID,
                           attachment.FileName
                          )
                      Else
                          navigationUrl = attachment.VirtualPath
                      End If
                  End If
 
                  acc2.Add(New With {
                   Key .Name = type.Name,
                 .ID = attachment.ID,
                 .Subject = attachment.Subject,
                 .FileName = attachment.FileName,
                 .CreatedDate = String.Format("{0} {1}", attachment.CreatedDate.ToString(CurrentCulture.DateTimeFormat.ShortDatePattern, CurrentCulture), attachment.CreatedDate.ToString(CurrentCulture.DateTimeFormat.ShortTimePattern, CurrentCulture)),
                 .CreatedBy = attachment.CreatedBy,
                  .AttachmentUrl = navigationUrl
                  })
                  Return acc2
              End Function
             )
             Return acc
         End Function
        )
 
        DirectCast(grdAttachments.Columns(1), GridHyperLinkColumn).DataNavigateUrlFormatString = String.Format("{0}hj/ts/displ.aspx?id={1}0{2}", Captions.VirtualRoot, Chr(123), Chr(125))
 
        grdAttachments.DataSource = attachments.ToArray()
 
         
    End Sub
is the Grid and the Databinding
.Thanks in Advance
Jose

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Nov 2013, 09:50 AM
Hi Joselina,

Please try the following code snippet.

VB:
Protected Sub RadGrid1_PreRender(sender As Object, e As System.EventArgs) Handles RadGrid1.PreRender
  
      For Each groupHeaderItem As GridGroupHeaderItem In grdAttachments.MasterTableView.GetItems(GridItemType.GroupHeader)      
            groupHeaderItem.DataCell.Text = groupHeaderItem.DataCell.Text + "(" + groupHeaderItem.GetChildItems().Length.ToString() + ")"      
       Next
  
End Sub

Thanks,
Shinu
0
Joselina
Top achievements
Rank 1
answered on 21 Nov 2013, 09:28 PM
Thank you so much Shinu. Your code helped me lot and its working fine. let me know some links to learn Telerik well.
0
Shinu
Top achievements
Rank 2
answered on 22 Nov 2013, 04:29 AM
Hi Joselina,

You can go through the documentation on RadControls for ASP.NET AJAX Documentation to understand about Telerik and its controls for ASP.NET AJAX.For live demo examples please look into Telerik Demos.

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