因为在silverlight中的ComboBox绑定数据要用到List对象,不知道MSsql数据库里的记录如何才能填充到List中,请大家给个范例,谢谢这是网上找到的Web service代码public class BlogService : WebService
{
    [WebMethod]
    public Post[] GetPosts()
    {
        List<Post> posts = new List<Post>()
        {
            new Post{ Id=1, Title="一步一步学Silverlight 2系列(13):数据与通信之WebRequest", Author="TerryLee" },
            new Post{ Id=2, Title="一步一步学Silverlight 2系列(12):数据与通信之WebClient", Author="TerryLee" },
            new Post{ Id=3, Title="一步一步学Silverlight 2系列(11):数据绑定", Author="TerryLee" },
            new Post{ Id=4, Title="一步一步学Silverlight 2系列(10):使用用户控件", Author="TerryLee" },
            new Post{ Id=5, Title="一步一步学Silverlight 2系列(9):使用控件模板", Author="TerryLee" },
            new Post{ Id=6, Title="一步一步学Silverlight 2系列(8):使用样式封装控件观感", Author="TerryLee" }
        };        return posts.ToArray();
    }
}
这个例子中是直接添加的数据,不知道从数据库取出来的数据有没有办法一次性转换成List对象?如果没有只好用遍历来填充了

解决方案 »

  1.   

    非要 List 么, 不是 IList 么, 数据库拿来的数据绑定是一般用的 dataview支持的接口:
    public class DataView : MarshalByValueComponent, IBindingListView, IBindingList, IList, 
    ICollection, IEnumerable, ITypedList, ISupportInitializeNotification, ISupportInitialize
      

  2.   

    使用一个info类QrenInfo 
    List<Post> posts = new List<Post>()
    while (查询结果)
    {
    QrenInfo info= new QrenInfo ();
    info.CPLBMC = dr["CPLBMC"].ToString();posts.add(info);
    }
      

  3.   

    创建一个list 然后遍历就可以实现
      

  4.   

    List<T> l=new List<T>;
    通过遍历数据集,赋值给类实例属性,添加类到List泛型里