在asp.net gridview中显示选择性列

时间:2011-10-10 21:43:45

标签: asp.net vb.net visual-studio-2008 gridview directoryinfo

这是对我上一个问题的跟进:Filter DirectoryInfo files by date in asp.net

我有一个gridview,它从DirectoryInfo填充数据 但是,我只想显示某些列,并自定义行中的列名和超链接值。

我的代码是:

Dim files As FileInfo() = New DirectoryInfo(strDirectoryPath).GetFiles().Where(Function(x) x.LastWriteTime >= (dtStartDate) AndAlso x.LastWriteTime <= (dtEndDate)).ToArray()  

For Each col In Gridview.Columns
If InStr(1, ",name,Extension,LastWriteTime,", "," & col.ColumnName.ToString.Trim & ",") > 0 Then
                        Dim hfield As HyperLinkField = New HyperLinkField()
                        hfield.DataTextField = col.ColumnName
                        hfield.HeaderText = "<table><tr><td align=""center"">" & col.ColumnName & "</td></tr></table>"
                        gvInvoiceList.Columns.Add(hfield)
                        i += 1
                    End If
Next

问题:
如何循环遍历列,仅显示“name”,“extension”和LastWriteTime?

1 个答案:

答案 0 :(得分:0)

只需customize the GridView columns,仅列出您想要的内容。但是,如果确实想要在列名称标题中使用嵌套表格,则需要转而使用Repeater或ListView。