Group by first letter

Posted by: zev on 27 February 2019, 4:08 pm EST

    • Post Options:
    • Link

    Posted 27 February 2019, 4:08 pm EST

    Hi. I have been asked to create a list a persons grouped by first letter. So all the A’s would be under A, etc. I have a feeling that this can be done, I just can’t quite figure out how to do it.

  • Posted 28 February 2019, 6:58 am EST

    Hello,

    To achieve your requirement, you can store the required data in a DataTable where one column contains the initials of the names of the people. This can be obtained using the Substring method of a string.

    A report layout is created such that the report is grouped based on the DataField with initials of the names.

    Further, data from the DataTable can be sorted using a View and then used as a DataSource to the report. This is done as follows:

    private void SectionReport1_ReportStart(object sender, EventArgs e)
           {
               DataView dv= GetDataTable().DefaultView;
               dv.Sort = "Person ASC";
               this.DataSource = dv;
           }
    

    Here, GetDataTable() returns the DataTable.

    An application has been attached for your reference.

    Best Regards,

    Esha

    prj_SectionReport_GroupAlphabetically.zip

  • Posted 28 February 2019, 6:12 pm EST

    Hi, thanks your your reply. I was hoping there would be a way to do it with some kid of calculation. Like getting the initial directly from field value in the report viewer and then grouping on the results.

  • Posted 1 March 2019, 10:39 am EST

    Hello,

    You can create a “Calculated Field” with Formula “FieldName.Substring(0, 1)”. After that use the calculated field in “DataField” property of the Group. Please refer to the attached report.

    Thanks.

    rpt_Section.zip

  • Posted 1 March 2019, 10:43 am EST - Updated 30 September 2022, 5:49 pm EST

  • Posted 1 March 2019, 12:12 pm EST

    thanks!

  • Posted 4 March 2019, 5:38 pm EST

    Hi. I tried adding a calculated field, and then grouping by that field. I also put the calculated field in the group header. Problem is it sisn’t work. It didn’t group, and the calculated field in the header was blank. Below is the xml. what am I doing wrong?

    <?xml version="1.0" encoding="UTF-8"?>
  • Posted 5 March 2019, 1:51 am EST

    Hello,

    Have you bound the report with any datasource? Because the “DataSource” part is missing in the above XML file. You have to bind the report with datasource to use the datafield. Also, please sort your SQL query according to “Name” field like below to use for grouping in the section report:

    Select * from Table Order by Name

    Hope it clarifies.

    Thanks.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels