Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用会话列表<;t>;在asp.net中刷新页面时_C#_Asp.net - Fatal编程技术网

C# 如何使用会话列表<;t>;在asp.net中刷新页面时

C# 如何使用会话列表<;t>;在asp.net中刷新页面时,c#,asp.net,C#,Asp.net,我有列表,用于使用拖放功能在中继器控件中显示数据 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"}); 在页面加载时,我在转发器中显示了这些数据 现在我想从列表中删除一个“item2”并在repeater上显示agi

我有
列表
,用于使用拖放功能在中继器控件中显示数据

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"});
在页面加载时,我在转发器中显示了这些数据

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

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


我如何才能做到这一点?

如下更改getDate

 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;
 } 
公共静态列表getdata()
{
List LeftSideList=新列表();
如果(会话[“左侧”]!=null)
{
LeftSideList=(列表)会话[“leftside”];
}
其他的
{
Add(新的DragAndDropData{Id=0,Name=“Item1”});
Add(新的DragAndDropData{Id=1,Name=“Item2”});
Add(新的DragAndDropData{Id=2,Name=“Item3”});
Add(新的DragAndDropData{Id=3,Name=“Item4”});
Add(新的DragAndDropData{Id=4,Name=“Item5”});
}
返回左侧列表;
} 
对于您的问题:

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

通过自定义变量从列表中选择项目的一种可能性是在
DragAndDropData
-类中实现
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"));