When I call the following method as a datasource of a dropdownlist, I get System.Data.DataRowView instead of folder names. Where am I doing wrong?
public DataTable listFolders()
{
DataTable dt = new DataTable();
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("fullname", typeof(string));
string defaultPath = Server.MapPath(ConfigurationManager.AppSettings["defaultPath"].ToString());
foreach (var dir in new DirectoryInfo(defaultPath).GetDirectories("*", SearchOption.TopDirectoryOnly))
{
dr = dt.NewRow();
dr["name"] = dir.Name;
dr["fullname"] = dir.FullName;
dt.Rows.Add(dr);
}
return dt;
}
My method call
ddl.DataSource = listFolders();
ddl.DataBind();