开发者

How to populate a listview from a datatable

I have a ListView and a DataTable and I would like to know how to populate the ListView from the DataTable.

Here is my code:

DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(@"connectionstring");
SqlCommand ccmd = new SqlCommand("SELECT img FROM '" + user + "'", conn);
conn.Open();

SqlDataAdapter da开发者_如何学JAVA = new SqlDataAdapter(ccmd);
da.SelectCommand = ccmd;
da.Fill(dt);


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜