我正在尝试将超链接字段列添加到从服务器上的文件目录中提取文件名的 GridView。我正在使用下面的代码,但它并不完全有效。它显示了路径和文件名,但它不是可点击的超链接字段。我不确定我做错了什么,有人可以帮助我吗?
public void GetFilesAndFolders()
{
using (IREPEntities dbContext = new IREPEntities())
{
String vcharTempFileLocation = (from a in dbContext.tbl_ApplicationSetting
where a.vcharKey == "vcharTempFileLocation"
select a).Single().vcharValue;
DataTable gridviewSource = DisplayFilesInGridView();
DataRow gridviewRow;
//Get All Folders Or Directories and add in table
DirectoryInfo directory = new DirectoryInfo(vcharTempFileLocation);
DirectoryInfo[] subDirectories = directory.GetDirectories();
foreach (DirectoryInfo dirInfo in subDirectories)
{
gridviewRow = gridviewSource.NewRow();
gridviewRow["Claim"] = ddlClaimNumber.SelectedItem;
gridviewRow["Name"] = dirInfo.Name;
dynamic newlink = new HyperLinkField();
newlink = vcharTempFileLocation + dirInfo.Name;
gridviewRow["link"] = newlink;
gridviewRow["Application"] = chkApplicationType.SelectedItem;
gridviewSource.Rows.Add(gridviewRow);
}
//Get files in all directories
FileInfo[] files = directory.GetFiles("*.*", SearchOption.AllDirectories);
foreach (FileInfo fileInfo in files)
{
gridviewRow = gridviewSource.NewRow();
gridviewRow["Claim"] = ddlClaimNumber.SelectedItem;
gridviewRow["Name"] = fileInfo.Name;
dynamic newlink = new HyperLinkField();
newlink = vcharTempFileLocation + fileInfo.Name;
gridviewRow["link"] = newlink;
gridviewRow["Application"] = chkApplicationType.SelectedItem;
gridviewSource.Rows.Add(gridviewRow);
}
gvBatchDetails.DataSource = gridviewSource;
gvBatchDetails.DataBind();
}
}
private DataTable DisplayFilesInGridView()
{
DataTable dtgridviewSource = new DataTable();
dtgridviewSource.Columns.Add(new DataColumn("Claim", typeof(System.String)));
dtgridviewSource.Columns.Add(new DataColumn("Name", typeof(System.String)));
dtgridviewSource.Columns.Add(new DataColumn("Application", typeof(System.String)));
dtgridviewSource.Columns.Add(new DataColumn("link", typeof(System.String)));
return dtgridviewSource;
}
}