在 ASP.NET 网格视图中显示选择性列
这是我上一个问题的后续问题:按日期过滤 DirectoryInfo 文件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
问题:
如何循环遍历列,以仅显示“名称”、“扩展名”和 LastWriteTime?
This is a follow up to my previous question: Filter DirectoryInfo files by date in asp.net
I have a gridview that is populating data from DirectoryInfo.
However, I only want to display certain columns, and customize the column names and the hyperlink value in the row.
My code is:
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
Question:
How can I loop through the columns, to display only "name", "extension" and LastWriteTime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需自定义 GridView 列 ,仅列出您想要的。不过,如果您确实想要在列名称标题中使用类似嵌套表格的内容,则需要改为使用 Repeater 或 ListView。
Just customize the GridView columns, listing only the ones you want. Though, if you really want something like a nested table in your column name header, you'll need to step up to a Repeater or ListView instead.