[英]Bind complex list to datasource a gridview
whether possible Bind complex list to DataSource a GridView with all members?是否可能将复杂列表绑定到 DataSource a GridView 和所有成员?
such as:如:
public class Car
{
private string _make;
private string _model;
private int _year;
private int _speedCollection;
public Car(string make, string model, int year)
{
_make = make;
_model = model;
_year = year;
}
public string Make
{
get { return _make; }
set { _make = value; }
}
public string Model
{
get { return _model; }
set { _model = value; }
}
public int Year
{
get { return _year; }
set { _year = value; }
}
public List<MyClass> SpeedColections
{
get { return _speedCollection; }
set { _speedCollection = value; }
}
}
public class MyClass
{
private int _speed;
public int Speed
{
get { return _speed; }
set { _speed = value; }
}
}
Yes, it is possible.是的,有可能。 And it will work, except for the
SpeedCollections
member, unless you specify another public member that would return, say, a string representation of Speed
(comma separated values or something of this sort)它会工作,除了
SpeedCollections
成员,除非你指定另一个公共成员,它会返回,比如说, Speed
的字符串表示(逗号分隔值或类似的东西)
Update更新
This is an example of a member that would return a string representation of SpeedCollections
:这是将返回
SpeedCollections
的字符串表示形式的成员示例:
Warning, Potential pseudo-code ahead, I cannot currently compile or test, so make your adjustments when needed
警告,前方可能存在伪代码,我目前无法编译或测试,因此请在需要时进行调整
public string SpeedRepresentation
{
get
{
return string.Join(",",
_speedCollection.Select(s => s.Speed().ToString())
.ToArray());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.