## 4 replies

Last post Nov 22, 2016 08:08 AM by Rammi44

• Rammi44

Member

12 Points

28 Posts

### Repeat each row after given SPK_REPEATcolumn value..

Table is is:

SPK_NAME SPK_ORDER SPK_REPEAT

SPK1                0                  0
SPK2                4                  0
SPK3                2                  2
SPK4                3                  0
SPK5                1                  2

Each speaker should repeat after repeat value and order by spk_order.

Result should:

SPK_NAME

SPK1

SPK5

SPK3

SPK4

SPK5

SPK3

SPK2

SPK5

SPK3

help me out this..

• Brando ZWZ

Contributor

6081 Points

1571 Posts

### Re: Repeat each row after given SPK_REPEATcolumn value..

Oct 28, 2016 08:15 AM|Brando ZWZ|LINK

Hi Rammi44,

#### Rammi44

Repeat each row after given SPK_REPEATcolumn value..

According to your description and demo, I couldn't understand the logic.

Why the SPK2 is at the header of "SPK_REPEAT= 2"'s group?

In my opinion, we will according to "SPK_REPEAT" column value to decide the spk_name order.

For example:

SPK_REPEAT = 0

SPK1

SPK5

SPK3

SPK4

SPK2

SPK_REPEAT = 1

SPK5

SPK3

SPK_REPEAT = 2

SPK5

SPK3

Best Regards,

Brando

• Rammi44

Member

12 Points

28 Posts

### Re: Repeat each row after given SPK_REPEATcolumn value..

Each row should repeat again after repeat rows(i.e spk_Repeat column value)

in give ex SPK5 has repeat after value is  2, that is after two rows it should repeat again.. after every two rows it should repeat..

• Brando ZWZ

Contributor

6081 Points

1571 Posts

### Re: Repeat each row after given SPK_REPEATcolumn value..

Nov 09, 2016 10:25 AM|Brando ZWZ|LINK

Hi Rammi44,

#### Rammi44

Each row should repeat again after repeat rows(i.e spk_Repeat column value)

in give ex SPK5 has repeat after value is  2, that is after two rows it should repeat again.. after every two rows it should repeat..

According to your description, I suggest you could firstly order the datatable.

Then you could loop the datatable, repeat the record.

More details, you could refer to follow codes:

```protected void Page_Load(object sender, EventArgs e)
{
DataTable d1 = new DataTable();

var newDataTable = d1.AsEnumerable()
.OrderBy(r => r.Field<int>("SPK_ORDER")).CopyToDataTable();

var Listrow  = d1.AsEnumerable()
.OrderBy(r => r.Field<int>("SPK_ORDER")).Select(x => x.Field<string>("SPK_NAME")).ToList();
int i = 0;
while (i <= Listrow.Count )
{
foreach (DataRow item in newDataTable.Rows)
{
if ((int)item["SPK_REPEAT"] != 0)
{
int index = Listrow.LastIndexOf(item["SPK_NAME"].ToString()) + (int)item["SPK_REPEAT"] + 1;
Listrow.Insert(index, item["SPK_NAME"].ToString());
if (i < index + (int)item["SPK_REPEAT"])
{
i = index + (int)item["SPK_REPEAT"];
}
}
}
}
GridView1.DataSource = Listrow;
GridView1.DataBind();
}```

Result:

Best Regards,

Brando

• Rammi44

Member

12 Points

28 Posts