如何从数据表填充列表视图 [英] How to populate a listview from a datatable

查看:25
本文介绍了如何从数据表填充列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView 和一个 DataTable,我想知道如何从 DataTable 填充 ListView代码>.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆