0

我必须list<class>使用拖放在中继器控件中显示数据。

list.add(new class{id=0, name ="item1"});
list.add(new class{id=1, name ="item2"});
list.add(new class{id=2, name ="item3"});
list.add(new class{id=3, name ="item4"});

在页面加载时,我在Repeater中显示了这些数据......

现在我想从列表中删除一个“item2”并在中继器上显示 agian,

当我刷新页面时它也保持不变

我怎么能这样做?

4

2 回答 2

0

将getDate更改为Follow ...

 public static List<DragAndDropData> getdata()
 {
         List<DragAndDropData> LeftSideList=new List<DragAndDropData>();
         if(Session["leftside"]!=null)
         {
           LeftSideList=(List<DragAndDropData>)Session["leftside"];
         }
         else
         {
           LeftSideList.Add(new DragAndDropData { Id = 0, Name = "Item1" });
           LeftSideList.Add(new DragAndDropData { Id = 1, Name = "Item2" });
           LeftSideList.Add(new DragAndDropData { Id = 2, Name = "Item3" });
           LeftSideList.Add(new DragAndDropData { Id = 3, Name = "Item4" });
           LeftSideList.Add(new DragAndDropData { Id = 4, Name = "Item5" });

    }
         return LeftSideList;
 } 
于 2012-09-06T06:39:09.760 回答
0

对于你的问题:

现在我想从列表中删除一个“item2”并在中继器上显示 agian

通过自定义变量从列表中选择项目的一种可能性是IEquatable<DragAndDropData>在您的DragAndDropData-class 中实现。

请参阅MSDN IEquatable

在所需的方法中Equals,您可以比较变量Name是否相等。

public class DragAndDropData : IEquatable<DragAndDropData> {

  public string Name { get; set; }

  public Box(string n)
  {
    this.Name = n;
  }

  ...

  public bool Equals(DragAndDropData other) {
    return (this.Name == other.Name);
  }
}

完成此操作后,您应该能够找到并删除如下项目:

listcollection.Contains(new DragAndDropData("Item2"));
listcollection.Remove(new DragAndDropData("Item2"));
于 2012-09-06T07:34:47.030 回答