如何从数据表填充列表 [英] How to populate a listview from a datatable
本文介绍了如何从数据表填充列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 ListView
和一个 DataTable
,我想知道如何填充 ListView
从 DataTable
。
I have a ListView
and a DataTable
and I would like to know how to populate the ListView
from the DataTable
.
这是我的代码:
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(@"connectionstring");
SqlCommand ccmd = new SqlCommand("SELECT img FROM '" + user + "'", conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(ccmd);
da.SelectCommand = ccmd;
da.Fill(dt);
推荐答案
假设您已经设计了ListView(和绑定你的标记里面的代码是你在服务器端将数据加载到listView中的代码:
Assuming that you have already designed your ListView (and bindings inside it) in your markup here is the code you need in your server side to load data into listView:
listView.DataSource = dt;
listView.DataBind();
这篇关于如何从数据表填充列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文