这里对你来说有点复杂。我有一些代码列出了 GridView 中的文件及其大小、创建日期和修改日期等。我想在“文件名”列中添加一个超链接,但我一直无法找到执行此操作的方法。
我在后面的代码中构建了整个 GridView。
Sub BindGrid(path)
'Create GridView headings and add titles'
Dim dt As New DataTable
Dim Name As New HyperLinkField
dt.Columns.Add("FileName")
dt.Columns.Add("Size")
dt.Columns.Add("Last Accessed")
dt.Columns.Add("Created Date")
Dim Username = User.Identity.Name.ToString
Dim TrimUsername = Username.Replace("ASHDOWN\", "")
'Dim Path As String = "~\\Users\\" & TrimUsername''
LoginNameDisplay.Text = TrimUsername
Dim di As New IO.DirectoryInfo(Server.MapPath(Path))
Try
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
'list the names of all files in the specified directory'
For Each dra In diar1
dt.Rows.Add(New Object() {dra.Name, dra.Length & " KB", dra.LastAccessTime, dra.CreationTime})
Next
GridView1.DataSource = dt
GridView1.DataBind()
Catch ex As Exception
End Try
End Sub
这是我的 ASPX 页面代码
<asp:GridView ID="GridView1" Width="100%" runat="server" CellPadding="4"
EnableModelValidation="True" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField AccessibleHeaderText="Hyperlink" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
对此的任何帮助都会非常好。