Reputation: 3678
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 = new SqlDataAdapter(ccmd);
da.SelectCommand = ccmd;
da.Fill(dt);
Upvotes: 4
Views: 5965
Reputation: 13486
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();
Upvotes: 5