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();
精彩评论