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"));