数据包如果那么其他砖墙... [英] Databound if then else brick wall...

查看:62
本文介绍了数据包如果那么其他砖墙...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据绑定grideview,我想根据标准对我的aspx.vb后端的单元格进行颜色编码......我开始:



I have a databound grideview where I want to color-code the cells in my aspx.vb back end, based on criteria... I started with:

If IsDBNull(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = True Then
            e.Row.Cells(3).ForeColor = Drawing.Color.Black

Else
            e.Row.Cells(3).BackColor = Drawing.Color.Green

End If





***



这个有用了,所以我决定给它添加一些ElseIf语句,让它看看NullOrEmpty之间的区别,但是不能得到它语法正确。有几个例子,但无论出于何种原因,我没有超越第一个如果,没有其他任何东西被评估。我测试数据库值以强制更改单元格颜色,并且不能使单元格执行任何操作,只有白色和黑色文本(如果db为空)或绿色背景(Else)。任何人都可以帮我弄清楚我做错了什么? Guest是一个特定的值,我想搜索它,如果存在 - 一个特定的颜色。





***

This worked, so then I decided to add some ElseIf statements to it, and have it look at the difference between NullOrEmpty, but cannot get the syntax right. There are several examples, but for whatever reason, I am not getting past the first "If", nothing else is being evaluated. I test the database values to force a change in the cell color, and cannot make the cells do anything but White with Black Text (if db is null) OR Green Background (Else). Can anyone help me figure out what I am doing wrong? "Guest" is a specific value, for which I want to search, and if present - a specific color.

If (e.Row.RowType <> DataControlRowType.DataRow) Then
    Exit Sub
End If
If IsDBNull(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = True Then
    e.Row.Cells(3).ForeColor = Drawing.Color.Black
ElseIf Len(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = 0 Then
    e.Row.Cells(3).BackColor = Drawing.Color.Black
ElseIf DataBinder.Eval(e.Row.DataItem, "SwitchPort1").ToString = "" Then
    e.Row.Cells(3).BackColor = Drawing.Color.Blue
ElseIf DataBinder.Eval(e.Row.DataItem, "SwitchPort1").ToString = "Guest" Then
    e.Row.Cells(3).BackColor = Drawing.Color.Yellow
Else
    e.Row.Cells(3).BackColor = Drawing.Color.Green
End If





我的尝试:



我曾尝试查看各种不同的网站以查找参考资料,但没有什么能以我理解的方式解释事物。我已经尝试过测试多行更改,Dim String语句和测试字符串,但我只是碰壁砖。



What I have tried:

I have tried looking at various different sites to find references, but nothing is really explaining things in a way I understand. I have tried testing numerous lines of changes, Dim String statements, and testing the String, but I am just hitting a brick wall.

推荐答案

如果我理解你的话。 ..我建议使用词典课来简化这一过程。 [ ^ ]。



请参阅:

If i understand you well... i'd suggest to simplify this by using Dictionary class[^].

See:
'define "color translator" ;)
Dim ColorTranslator As Dictionary(Of String, Drawing.Color) = New Dictionary(Of String, Drawing.Color)
'add keys and values
With ColorTranslator
	.Add("-1", Drawing.Color.Black)
	.Add("0", Drawing.Color.Black)
	.Add("", Drawing.Color.Blue)
	.Add("Guest", Drawing.Color.Yellow)
End With

'...
'later
'...

Dim sVal As String = DataBinder.Eval(e.Row.DataItem, "SwitchPort1").ToString()
e.Row.Cells(3).BackColor = If(Not ColorTranslator.ContainsKey(sVal), Drawing.Color.Green, ColorTranslator(sVal))


这篇关于数据包如果那么其他砖墙...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆