自动生成列的,怎么取列名
解决方案 »
- 如何屏蔽或者去掉父类的PAGE_LOAD事件
- 如何在.NET的页面中实现快捷键功能
- 怎样打开下载的asp.net(c#源码)程序,如何使它运行
- 关于datagrid控件的问题
- 怎样从库中绑定数据显示出图片来后让图片有一个超连接
- 给两个时间。比如2004-6 2007-9 怎么求出当中的年月啊如2004-7 2004-8 2004-9 等 然后把这些时间取出来。放在哪里好呢。怎么遍历啊
- GridView处理和展示问题
- 求助!如何将含有dropdownlist控件(非编辑状态)的datagrid里的数据导出到excel或word里?
- TreeView的使用求高手帮忙
- 急:求asp.net(C#)播放rm文件的源代码
- DataList控件的使用問題?
- 这个SQL语句怎么会有错误???
If e.Item.ItemType = ListItemType.Header Then
str=e.Item.Cells(i).Text
End if第一行是判断是否为头
如果是,取出这个头的名字。
同理还有:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
...
End IF
这个是内容项(当然需要名括交替项)有这两个判断,不仅可以动态取出列名,还可以根据列名,动态的翻译列名,动态翻译内容,动态为列设定数据格式等等...
Dim i As Integer
'头部分
If e.Item.ItemType = ListItemType.Header Then Formats = New String(e.Item.Cells.Count - 1) {}
For i = 0 To e.Item.Cells.Count - 1
Formats(i) = "M"'初始格式化信息,避免为空
Next
For i = 0 To e.Item.Cells.Count - 1
If e.Item.Cells(i).Text = "CS" Then
Formats(i) = "0.00"
e.Item.Cells(i).Text = "平均车速"
ElseIf e.Item.Cells(i).Text = "CSL" Then
e.Item.Cells(i).Text = "车数"
ElseIf e.Item.Cells(i).Text = "JZ" Then
e.Item.Cells(i).Text = "净重"
ElseIf e.Item.Cells(i).Text = "LB" Then
e.Item.Cells(i).Text = "类别"
Formats(i) = "T"
ElseIf e.Item.Cells(i).Text = "SHDWNAME" Then
e.Item.Cells(i).Text = "收货单位"
End If
Next
'内容部分
ElseIf e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim j As Integer
For j = 0 To e.Item.Cells.Count - 1
If Formats(j) = "T" Then
If Trim(e.Item.Cells(j).Text) = "J" Then e.Item.Cells(j).Text = "购进"
If Trim(e.Item.Cells(j).Text) = "C" Then e.Item.Cells(j).Text = "售出"
End If
If Formats(j) = "0.00" Then
e.Item.Cells(j).Text = CType(e.Item.Cells(j).Text, Double).ToString(Formats(j))
End If Next
End If