如何将泛型集合的数据传到listview中
vehicle=newDictionary<string,Vehicle>();Carcar=newCar("京R00000","奥迪A6","黑色",3,240);Tr...
vehicle = new Dictionary<string, Vehicle>();
Car car = new Car("京R00000","奥迪A6","黑色",3,240);
Truck truck = new Truck("京D11111","东风","蓝色",3,240,20);
vehicle.Add(car.CarNum,car);
vehicle.Add(truck.CarNum,truck); 展开
Car car = new Car("京R00000","奥迪A6","黑色",3,240);
Truck truck = new Truck("京D11111","东风","蓝色",3,240,20);
vehicle.Add(car.CarNum,car);
vehicle.Add(truck.CarNum,truck); 展开
1个回答
展开全部
ListView是显示数据的,
List<string> myList=new List<string>();
myList.Add("aaa");
myList.Add("bbb");
myList.Add("ccc");
ListView1.DataSouce=myList;
ListView1.Databind();
就行了
-------------------------------------------------------------
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="groupPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<GroupTemplate>
<div>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</div>
</GroupTemplate>
<ItemTemplate>
<%#Container.DataItem %>
</ItemTemplate>
</asp:ListView>
public void bind()
{
Dictionary<string, Vehicle> myCollection = new Dictionary<string, Vehicle>();
Car car = new Car("京R00000", "奥迪A6", "黑色");
Tank tank = new Tank("京D11111", "东风", "蓝色");
myCollection.Add(car.CarNum, car);
myCollection.Add(tank.CarNum, tank);
//List<string> myCollection = new List<string>();
//myCollection.Add("df");
//myCollection.Add("dfwe");
//myCollection.Add("dferere");
ListView1.DataSource = myCollection;
ListView1.DataBind();
}
List<string> myList=new List<string>();
myList.Add("aaa");
myList.Add("bbb");
myList.Add("ccc");
ListView1.DataSouce=myList;
ListView1.Databind();
就行了
-------------------------------------------------------------
<asp:ListView ID="ListView1" runat="server">
<LayoutTemplate>
<asp:PlaceHolder ID="groupPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<GroupTemplate>
<div>
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</div>
</GroupTemplate>
<ItemTemplate>
<%#Container.DataItem %>
</ItemTemplate>
</asp:ListView>
public void bind()
{
Dictionary<string, Vehicle> myCollection = new Dictionary<string, Vehicle>();
Car car = new Car("京R00000", "奥迪A6", "黑色");
Tank tank = new Tank("京D11111", "东风", "蓝色");
myCollection.Add(car.CarNum, car);
myCollection.Add(tank.CarNum, tank);
//List<string> myCollection = new List<string>();
//myCollection.Add("df");
//myCollection.Add("dfwe");
//myCollection.Add("dferere");
ListView1.DataSource = myCollection;
ListView1.DataBind();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询