简体   繁体   中英

Repeater - compare items and group

I have a repeater and at the moment in my first column which is the console type column it displays:

under my column header: PS4, PS4, PS4, XBOX ONE, XBOX ONE, Nintendo wii

so it is sorting it but I want it to group so that it only shows one console once I think there should be a way to compare dataItemRow with previous dataItemRow but not really sure how. Any Suggestions?

void rptItems_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        //code here that goes through all items and compares items

    }
}

population:

       SqlDataAdapter da = new SqlDataAdapter("Stored Procedure", conn);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;
        da.SelectCommand.Parameters.Add(new SqlParameter("@Admin", "ALL"));
        DataSet dataset = new DataSet();
        da.Fill(dataset);
        rptItems.DataSource = dataset.Tables[0];
        rptItems.DataBind();

The main idea behind is to use two repeater controls (any template based rendering controls). The outer repeater control's ItemTemplate will host the header information and inner repeater control. The inner repeater control will host the records corresponding to the header (Group By column)

The main logic in Item databound is

  1. Get the record being bound and get all the records corresponding to group by column and add those into temporary list
  2. Build the header information with the values from the record being bound
  3. Bind the records from tempoarary list (from 1) into the inner repeater
  4. Ignore the record being bound and other records of the same group

If you want code help let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM