Repeater control for data aggregation?

I have a spreadsheet with doctors and doctors in these offices, which I fill out in the repeater. The returned data is not aggregated. So, if 1 office has 2 doctors, there are 2 rows, one office, another doctor.

Is there a way to combine the data so that the repeater shows 1 office with all doctors from that office so that I can avoid duplication?

0


source to share


4 answers


In your aspx markup:

<table><tr><th>Office</th><th>Doctors</th></tr>
<asp:repeater id="Repeater" runat="server" OnItemDataBound="NextItem" ... >
    <ItemTemplate><asp:Literal id="RepeaterRow" runat="server" />
    </ItemTemplate>
</asp:repeater>
<asp:Literal id="LastRow" runat="server" />
</table>

      

In your code behind:



public class Office
{
    public string OfficeName {get;set;};
    List<string> _doctors = new List<string>();
    public List<string> Doctors {get{ return _doctors; } };

    void Clear()
    {
        OfficeName = "";
        _doctors.Clear();
    }

    public override string ToString()
    {
        StringBuilder result = new StringBuilder("<tr>");

        result.AppendFormat("<td>{0}</td>", OfficeName);

        string delimiter = "";
        result.Append("<td>");
        foreach(string doctor in Doctors)
        {
           result.Append(doctor).Append(delimiter);
           delimiter = "<br/>";
        }

        result.Append("</td></tr>");

        return result.ToString();
    }
}

      

...

private string CurOffice = "";
private Office CurRecord = new Office();

void NextItem(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) return;

    Literal repeaterRow = e.Item.FindControl("RepeaterRow") as Literal;
    if (repeaterRow == null) return;

    DataRow row = ((DataRowView)e.Item.DataItem).Row;

    if ( CurOffice != (string)row["Office"] )
    {
        repeaterRow.Text = CurRecord.ToString();
        repeaterRow.Visible = true;

        CurRecord.Clear();
        CurOffice = row["Office"];
        CurRecord.Office = CurOffice;
    }
    else
        e.Item.Visible = false;

    CurRecord.Doctors.Add((string)row["doctor"]);
}

void Page_PreRender(object sender, EventArgs e)
{
    LastRow.Text = CurRecord.ToString();
}

      

+1


source


I think your best bet is to do the aggregation on the database.



0


source


I was looking into this but thought there might be a more convenient way to do this.

If aggregating in db, skip the divisible column and parse it during data binding?

0


source


Use the SQL coalition function

As from SQLTeam.com:

DECLARE @EmployeeList varchar(100)

SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') + 
       CAST(Emp_UniqueID AS varchar(5))
FROM SalesCallsEmployees
WHERE SalCal_UniqueID = 1

      

This will create a comma-delimited list of employees. You can do this for doctors too.

0


source







All Articles