[SOLVED] How to reorder, delete and render DataRepeater item?

Answered Closed
0
0

Hi Wisej,

The new feature DataRepeater is amazing. Thanks for your hard work.

For my case, users would love to reorder or delete item. Could you give any advice or best practice to implement this?

Right now DataRepeaterItem’s ItemIndex property and ComboBox seems not working as expected.

Thank you.

Frank


Update: Version 2.1.7 fixed all bugs.

I cleaned up example code a little bit, for whom might be interested in how to use DataRepeater later.

  • You must to post comments
Best Answer
0
0

Thank you for the sample. All the issues you reported have been fixed and will be in the next beta update. In general:

To swap items:

private void btnUp_Click(object sender, EventArgs e)
{
var x = DataRepeater1.CurrentItemIndex;
var l = employeesList;
var t = l[x];
l[x] = l[x – 1];
l[x – 1] = t;
}

private void btnDown_Click(object sender, EventArgs e)
{
var x = DataRepeater1.CurrentItemIndex;
var l = employeesList;
var t = l[x];
l[x] = l[x + 1];
l[x + 1] = t;
}

To delete:

private void btnDelete_Click(object sender, EventArgs e)
{
var x = DataRepeater1.CurrentItemIndex;
var l = employeesList;
l.RemoveAt(x);
}

Do not use DataRepeater1_ItemTemplate_Appear since it’s the “appear” event of the template when it’s rendered on the browser and if you change the template then you are changing all the new items getting cloned from the template. To post process a repeater item use one of these events:

ItemCloned

ItemUpdate

 

 

 

  • Frank Xu
    Hi Luca, Thanks a lot for your help! Looking forward for next release. Would like to confirm for next release, after list changed var l = employeesList; var t = l[x]; l[x] = l[x + 1]; l[x + 1] = t; Will DataRepeater’s items change position automatically as well? If not, how can I do this? What I can think of is refreshing DataRepeater. However, it doesn’t work in current version. It’s also too expensive if list is huge? private void btnUp_Click(object sender, EventArgs e) { var nCurr = (int)DataRepeater1.CurrentItemIndex; int nAbve = nCurr – 1; var l = employeesList; var t = l[nCurr]; l[nCurr] = l[nAbve]; l[nAbve] = t; var newLst = new BindingList(); foreach (var empl in employeesList) { newLst.Add(empl); } DataRepeater1.DataSource = newLst; DataRepeater1.Update(); DataRepeater1.Refresh(); } Thank you.
  • You must to post comments
0
0

Update: Version 2.1.7 fixed all bugs.

I cleaned up example code a little bit, for whom might be interested in how to use DataRepeater later.

  • You must to post comments
0
0

Hi Frank,

all fixes are included in the latest Wisej beta (2.1.7).

Best regards
Frank

  • Frank Xu
    Thanks, Frank! It’s perfect.
  • You must to post comments
0
0

There is almost never a need to call Update or Refresh directly with Wisej. Update() simply marks the component dirty and it’s done already by all the properties. You should call Update() only when implementing a custom control and adding a property that should mark the component dirty. Refresh() is similar to Update() but it also invalidates all the previously rendered properties and causes all the properties to be set again on the client.

To answer your question, just changing the data source (when using BindingList like in our case, or a BindingSource) automatically updates the DataRepeater. You can add, remove, assign items and the DataRepeater is updated. No need to reassign the data source.

 

  • You must to post comments
0
0

Hi Luca,

Thanks a lot for your help! Looking forward for next release.

Would like to confirm for next release, after list changed

var l = employeesList;
var t = l[x];
l[x] = l[x + 1];
l[x + 1] = t;

Will DataRepeater’s items change position automatically as well?

If not, how can I do this? What I can think of is refreshing DataRepeater. However, it doesn’t work in current version. It’s also too expensive if list is huge?

private void btnUp_Click(object sender, EventArgs e)
{
var nCurr = (int)DataRepeater1.CurrentItemIndex;
int nAbve = nCurr – 1;
var l = employeesList;
var t = l[nCurr];
l[nCurr] = l[nAbve];
l[nAbve] = t;
var newLst = new BindingList<Employee>();
foreach (var empl in employeesList) {
newLst.Add(empl);
}
DataRepeater1.DataSource = newLst;
DataRepeater1.Update();
DataRepeater1.Refresh();
}

Thank you.

  • You must to post comments
Showing 5 results