数据绑定错误,以获取gridview上的Windows文件 [英] Databinding error to get windows files on gridview
本文介绍了数据绑定错误,以获取gridview上的Windows文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试在ASP.Net GridView上加载Windows文件,但是当我尝试此代码时,我收到此DataBinding错误消息,如下所示。 DataBinding:'System.Web.UI.WebControls.ListItem'不包含名称为....的属性
可以有人请指教?百万谢谢!!
Trying to get Windows files to load on ASP.Net GridView, but I am getting this DataBinding error message when I tried this code, below. DataBinding: 'System.Web.UI.WebControls.ListItem' does not contain a property with the name....
Can someone please advise? Million Thanks!!
FileGrid.DataBind(); // this line is giving me the problem.
我的尝试:
What I have tried:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] filePaths = Directory.GetFiles(Server.MapPath("../Files/"));
List<listitem> files = new List<listitem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
// string fileName = Path.GetFileName(files.ToString());
}
FileGrid.DataSource = files;
FileGrid.DataBind(); // this line is giving me the problem.
}
}
推荐答案
这是解决问题后的语法(如下) (!的IsPostBack)。
This is the syntax (below) to solve the problem after (!IsPostBack).
DataTable dt = new DataTable();
dt.Columns.Add("File");
dt.Columns.Add("Size");
dt.Columns.Add("Type");
foreach (string strfile in Directory.GetFiles(Server.MapPath("../Meow_Directory/")))
{
FileInfo fi = new FileInfo(strfile);
dt.Rows.Add(fi.Name, fi.Length.ToString(),
GetFileType_ByExtension(fi.Extension));
}
FileGrid.DataSource = dt;
FileGrid.DataBind();
这篇关于数据绑定错误,以获取gridview上的Windows文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文