Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.net(vb)从tablecell访问列号_Asp.net_Vb.net - Fatal编程技术网

ASP.net(vb)从tablecell访问列号

ASP.net(vb)从tablecell访问列号,asp.net,vb.net,Asp.net,Vb.net,在循环遍历每个单元格时,我试图找出整数所在的列: For Each cell As TableCell In e.Row.Cells If caseType = 0 Then cell.BackColor = Color.Red ElseIf caseType = 1 Then cell.BackColor = Color.Blue

在循环遍历每个单元格时,我试图找出整数所在的列:

For Each cell As TableCell In e.Row.Cells
                If caseType = 0 Then
                    cell.BackColor = Color.Red
                ElseIf caseType = 1 Then
                    cell.BackColor = Color.Blue
                End If
            Next
基本上,我想根据给定行的当前列执行不同的操作

编辑:

我在循环中每次都添加了一个计数器,我想我可以用它来确定我在哪一列:

For Each cell As TableCell In e.Row.Cells
            System.Diagnostics.Debug.WriteLine(i)                
            If caseType = 0 Then
                cell.BackColor = Color.Red
            ElseIf caseType = 1 Then
                cell.BackColor = Color.Blue
            End If
            i = i + 1
        Next

我的表只有13列,但Writeline正在打印0-15。。。知道额外的三列是从哪里来的吗?

推断实际上是正确的,只需要一秒钟来解释代码。。。我的列标题始终相同,因此我可以检查标题文本与列编号:

For Each cell As TableCell In e.Row.Cells
                Header = GridView1.HeaderRow.Cells(i).Text
                System.Diagnostics.Debug.WriteLine(Header)
                If caseType = 0 Then
                    cell.BackColor = Color.Red
                ElseIf caseType = 1 Then
                    cell.BackColor = Color.Blue
                End If
                i = i + 1
            Next
现在如果我在某个专栏,我可以做我的脏活了


谢谢

看来你需要这样的东西不,那帮不了我。。。我正试图得到我所在专栏的实际数字。。。不是标题名。。。我的表有13列。。。因此,我希望能够循环并获得实际的数字0、1、2、3、4、5、6、7、8、9、10、11、12抱歉,我不明白,您处于rowdatabound事件中,如果您使用for来代替foreach,会出现什么问题?那么标题解决方案实际上更好。。。因为如果我以后添加datagrid元素,我就不必担心更改代码了。。。因为每列的标题将保持不变。。。