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

DetailTables Aggregate value display in mastertable boundolumn

4 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joselina
Top achievements
Rank 1
Joselina asked on 06 Nov 2013, 07:36 PM
I am using Radgrid to display the number of attachements under each category. currently the boundcolumn has the datafield = "Name" (Name of the category) alone. If each category row from the master table view is clicked then it will be expanded to show the list of attachments under it, but now i have the requirement to show the count of the attachments also along with the Name of the Category in the Bouncolumn of the MasterTableview. 
BoundColCategory.DataField = "NAME"  + (deatailtable Items Count)
I want the output in the below format
Output Example: Attachment1(s) (20)
                         Attachment2(s) (10)
                         Attachment3(s) 
                        Attachment4(s) (5)
                        Attachment4(s) (11)
                        .........
                        .............
                        .............

I tried to set the datafield/text of the Boundcolumn in events like Item cretead or Pre- render and also in page load but not able to succeed Please help me how to achieve this programmmatically.
Below is the Grid in m
<am:aMGridID="amGrdNotesMaster"runat="server"TabIndex="212"AutoGenerateColumns="false"AllowSorting="false"AllowPaging="false"ClientSettings-AllowColumnsReorder="false"ClientSettings-AllowDragToGroup="false"ShowGroupPanel="false">
      <MasterTableViewDataKeyNames="ID"HierarchyDefaultExpanded="false"NoMasterRecordsText=""NoDetailRecordsText=""GroupLoadMode="Client">
                     <Columns>
                        <telerik:GridBoundColumnHeaderText="Category"DataField= "Name"UniqueName="Category"/>
                         <telerik:GridTemplateColumnUniqueName="Reorder">
                         <ItemTemplate><tm:TMButtonID="btnReorder"runat="server"CommandName="reorder"Text="Reorder based on sort"/></ItemTemplate>
                         </telerik:GridTemplateColumn>
                       </Columns>
                 <DetailTables>
                    <telerik:GridTableViewName="Detail"AllowSorting="true"AllowPaging="false"DataKeyNames="ID"NoMasterRecordsText=""NoDetailRecordsText=""EditMode="InPlace">
                      <Columns>
                         <telerik:GridBoundColumn Uniquename="ID" DataField ="ID" Aggregate ="Count" Visible ="true" ></telerik:GridBoundColumn>
                         <telerik:GridHyperLinkColumnUniqueName="Subject"HeaderText="Subject"DataNavigateUrlFormatString="~/notedisplay.aspx?id={0}"DataNavigateUrlFields="ID"DataTextField="Subject"SortExpression="Subject"ItemStyle-CssClass="gridhyperlink"HeaderStyle-Width="500px"/>
                         <telerik:GridHyperLinkColumnUniqueName="Attachment"HeaderText="Attachment"DataNavigateUrlFormatString="javascript:void(window.open('imageviewer.aspx?a=3&b=Attachment&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="AttachmentName"SortExpression="AttachmentName"ItemStyle-CssClass="gridhyperlink"/>
                         <telerik:GridBoundColumnUniqueName="AddDate"HeaderText="Created"DataField="AddDate"SortExpression="AddDate"ReadOnly="true"/>
                         <telerik:GridBoundColumnUniqueName="ModDate"HeaderText="Last Modified"DataField="ModDate"SortExpression="ModDate"ReadOnly="true"/>
                         <telerik:GridBoundColumnUniqueName="ModUser"HeaderText="Modified By"DataField="ModUser"SortExpression="ModUser"ReadOnly="true"/>
                        <telerik:GridNumericColumn  HeaderText="Position"DataField="SortOrder"SortExpression="SortOrder"UniqueName="SortOrder"/>
                        <telerik:GridEditCommandColumnUniqueName="EditColumn">
                        <ItemStyleCssClass="gridhyperlink"/>
                         </telerik:GridEditCommandColumn>
                       </Columns>
                     </telerik:GridTableView>
                  </DetailTables>
        </MasterTableView>
    <ClientSettingsAllowExpandCollapse="true">
   </ClientSettings>
  </am:aMGrid>
thanks
jose

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Nov 2013, 08:03 AM
Hello,

protected void Page_PreRender(object sender, EventArgs e)
       {
           foreach (GridDataItem item in amGrdNotesMaster.MasterTableView.Items)
           {
               int count = 0;
               if (item.HasChildItems)
               {
                   count = item.ChildItem.NestedTableViews[0].Items.Count;
               }
               item["Category"].Text = item["Category"].Text + "(" + count + ")";
           }
 
       }


Thanks,
Jayesh Goyani
0
Joselina
Top achievements
Rank 1
answered on 07 Nov 2013, 03:00 PM
Hi Jayesh,

Thanks for the reply but I am getting 0 as the count from the dataItem.ChildItem.NestedTableViews(0).Items.Count and also when the master table view dataitem got expanded then only it is displaying the count in the mastertable view bound column.

What could be the reason?

Thanks
Joselina
0
Shinu
Top achievements
Rank 1
answered on 08 Nov 2013, 11:12 AM
Hi Joselina,

Please set HierarchyLoadMode="Client" and try the following code snippet.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    int count = RadGrid1.MasterTableView.DetailTables.Count;
    foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
    {
        item["Category"].Text = item["Category"].Text + "(" + count + ")";         
    }
}

Thanks,
Shinu
0
Joselina
Top achievements
Rank 1
answered on 13 Nov 2013, 06:34 PM
Thanks shinu, I too used the same code and it is working fine now.

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