因为在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对象?如果没有只好用遍历来填充了
{
[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对象?如果没有只好用遍历来填充了
解决方案 »
- 无法获取 的内部内容,因为该内容不是文本。
- asp.net 2.0 有可以配置,程序出错提示就保存到指定的文件的配置方法吗?
- 请教asp.net(C#)如何 判断是否到数据库的第一条或者是最后一条(也就是EOF或BOF)
- session是不是一定要用Session.Clear清除?
- 求教:关于如何隐藏html页面的表格及改变单元格大小的问题(多谢)
- Asp.net msmq 消息队列发送失败问题
- 我想用RSA对字符加密,有谁有这个函数没有?
- ASP.NET连接MSSQL数据库问题
- 有关用户权限问题!关于权限继承,子系统权限控制等
- 快凌晨1:00了,熬夜的兄弟姐妹们,辛苦了,来领分吧
- 对ASP.NET三层的一些疑问。
- 产品表一般包含哪些字段
public class DataView : MarshalByValueComponent, IBindingListView, IBindingList, IList,
ICollection, IEnumerable, ITypedList, ISupportInitializeNotification, ISupportInitialize
List<Post> posts = new List<Post>()
while (查询结果)
{
QrenInfo info= new QrenInfo ();
info.CPLBMC = dr["CPLBMC"].ToString();posts.add(info);
}
通过遍历数据集,赋值给类实例属性,添加类到List泛型里