ASP.NET 2.0 GridView的HyperLinkField是可以向GridView添加超级链接列.
设置上与DataField有少许不同.
现在有一个DataTable作为GridView数据源,DataTable有3列,”FILE_NAMES”,”FILE_URL”,”ACCESS_TIME”含义是文件的名称,文件的URL,文件的上传时间.
绑定GridView代码如下
private void BindData()
{
this.GridView1.DataSource = GetAllManualName();
BindCol();
this.GridView1.DataBind();
}
private void BindCol()
{
HyperLinkField HycolTitle;
HycolTitle = new HyperLinkField();
HycolTitle.DataTextField = “FILE_NAMES”;
HycolTitle.HeaderText = “文件名称”;
HycolTitle.Target = “_blank”;
//设置DataNavigateUrlFields
string[] strs = {“FILE_URL”};
HycolTitle.DataNavigateUrlFields = strs;
GridView1.Columns.Add(HycolTitle);
}