正确的C#代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowIndex != -1 && ViewState["myDS"] != null){
DataSet ds = (DataSet)ViewState["myDS"];
for(int i=0;i<e.Row.Cells.Count;i++){
if (i >=7 && i<=9)
{
string str1 = ((Label)e.Row.Cells[i].Controls[1]).Text;
string str2 = "";
switch (i)
{
case 7:
str2 = ds.Tables[0].Rows[e.Row.RowIndex]["bet365_hwin"].ToString();
break;
case 8:
str2 = ds.Tables[0].Rows[e.Row.RowIndex]["bet365_draw"].ToString();
break;
case 9:
str2 =ds.Tables[0].Rows[e.Row.RowIndex]["bet365_awin"].ToString();
break;
}
if (str1 != str2)
{
double N1 = double.Parse(str1);
double N2 = double.Parse(str2); if (N1 != N2)
{
if (N1 > N2)
{
e.Row.Cells[i].BackColor = System.Drawing.Color.DarkSeaGreen;
}
else
{
e.Row.Cells[i].BackColor = System.Drawing.Color.Pink;
}
} }
}
}
}
}转成VB.NET代码后运行效果不同,代码如下:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowIndex <> -1 And Not (ViewState("myDS") Is Nothing) Then
Dim ds As DataSet = CType(ViewState("myDS"), DataSet)
Dim i As Integer
For i = 0 To e.Row.Cells.Count - 1
If i >= 7 And i <= 9 Then
Dim str1 As String = CType(e.Row.Cells(i).Controls(1), Label).Text
Dim str2 As String = ""
Select Case i
Case 7
str2 = ds.Tables(0).Rows(e.Row.RowIndex)("bet365_hwin").ToString()
Case 8
str2 = ds.Tables(0).Rows(e.Row.RowIndex)("bet365_draw").ToString()
Case 9
str2 = ds.Tables(0).Rows(e.Row.RowIndex)("bet365_awin").ToString()
End Select
If str1 <> str2 Then
Dim N1 As Double = Double.Parse(str1)
Dim N2 As Double = Double.Parse(str2) If N1 <> N2 Then
If N1 > N2 Then
e.Row.Cells(i).BackColor = System.Drawing.Color.Green
Else
e.Row.Cells(i).BackColor = System.Drawing.Color.Red
End If
End If
End If
End If
Next i
End If
End Sub我转成VB.NET后运行后和上面代码效果不一样,请问这段VB.NET代码哪里没转对,正确的应该是怎样的,谢谢!
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowIndex != -1 && ViewState["myDS"] != null){
DataSet ds = (DataSet)ViewState["myDS"];
for(int i=0;i<e.Row.Cells.Count;i++){
if (i >=7 && i<=9)
{
string str1 = ((Label)e.Row.Cells[i].Controls[1]).Text;
string str2 = "";
switch (i)
{
case 7:
str2 = ds.Tables[0].Rows[e.Row.RowIndex]["bet365_hwin"].ToString();
break;
case 8:
str2 = ds.Tables[0].Rows[e.Row.RowIndex]["bet365_draw"].ToString();
break;
case 9:
str2 =ds.Tables[0].Rows[e.Row.RowIndex]["bet365_awin"].ToString();
break;
}
if (str1 != str2)
{
double N1 = double.Parse(str1);
double N2 = double.Parse(str2); if (N1 != N2)
{
if (N1 > N2)
{
e.Row.Cells[i].BackColor = System.Drawing.Color.DarkSeaGreen;
}
else
{
e.Row.Cells[i].BackColor = System.Drawing.Color.Pink;
}
} }
}
}
}
}转成VB.NET代码后运行效果不同,代码如下:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowIndex <> -1 And Not (ViewState("myDS") Is Nothing) Then
Dim ds As DataSet = CType(ViewState("myDS"), DataSet)
Dim i As Integer
For i = 0 To e.Row.Cells.Count - 1
If i >= 7 And i <= 9 Then
Dim str1 As String = CType(e.Row.Cells(i).Controls(1), Label).Text
Dim str2 As String = ""
Select Case i
Case 7
str2 = ds.Tables(0).Rows(e.Row.RowIndex)("bet365_hwin").ToString()
Case 8
str2 = ds.Tables(0).Rows(e.Row.RowIndex)("bet365_draw").ToString()
Case 9
str2 = ds.Tables(0).Rows(e.Row.RowIndex)("bet365_awin").ToString()
End Select
If str1 <> str2 Then
Dim N1 As Double = Double.Parse(str1)
Dim N2 As Double = Double.Parse(str2) If N1 <> N2 Then
If N1 > N2 Then
e.Row.Cells(i).BackColor = System.Drawing.Color.Green
Else
e.Row.Cells(i).BackColor = System.Drawing.Color.Red
End If
End If
End If
End If
Next i
End If
End Sub我转成VB.NET后运行后和上面代码效果不一样,请问这段VB.NET代码哪里没转对,正确的应该是怎样的,谢谢!
解决方案 »
- .net AutoCompleteExtender,后置代码中写自动提示功能(急)
- 去掉小数点的问题
- 不知道是不是Session.Timeout的一个BUG
- 求 word 转 html;清除word垃圾代码;同时保证样式正常显示;
- excel文件打包成zip下载,但是出现中文乱码的问题?
- 超时时间已到。在操作完成之前超时时间已过或服务器未响应
- 我想能够一个机器上登录两个用户,但是这样记录两个用户的session,后一个会覆盖掉前一个,因为共用,可以解决吗?
- 在Global.asax中如何获得文件绝对物理路径?Server.MapPath不行的
- 100分求解,模式对话框如何能被父窗口关闭?(分不够再加)
- 求一个面试题的答案。
- 请求帮助:想实现无刷新的二级级联,但是老报——无法找到对象的错
- 各位大哥,小弟有个邮件接收的问题,请大家帮帮忙,在线等,急.......
否则的话,事件和代码没有绑定上!
If N1 > N2 Then
e.Row.Cells(i).BackColor = System.Drawing.Color.Green
Else
e.Row.Cells(i).BackColor = System.Drawing.Color.Red
End If
这句
e.Row.Cells(i).BackColor = System.Drawing.Color.Green 和
e.Row.Cells(i).BackColor = System.Drawing.Color.Red
不会变绿色或者红色,我断点看了都能看到n1 和 n2 的值。 C#代码就会改变颜色
帮忙看下是怎么回事,谢谢!
http://dotnet.csdn.net/aspnet-list.aspx?C=2e3f4d45-f5d3-4501-b21e-c0f9d2a431f9
可以变色
而VB.NET的 e.Row.Cells(i).BackColor = System.Drawing.Color.DarkSeaGreen
变不了色吗?难道VB.NET和C#不能实现同样的效果吗?
If Not e.Row.RowIndex Is -1 And ViewState("myDS") Is Nothing Then
Dim ds As DataSet = CType(ViewState("myDS"), DataSet)
Dim i As Integer
For i = 0 To e.Row.Cells.Count- 1 Step i + 1
If i >=7 And i<=9 Then
Dim str1 As String = (CType(e.Row.Cells(i).Controls(1), Label)).Text
Dim str2 As String = ""
Select Case i
Case 7
str2 = ds.Tables(0).Rows(e.Row.RowIndex)("bet365_hwin").ToString()
Exit For
Case 8
str2 = ds.Tables(0).Rows(e.Row.RowIndex)("bet365_draw").ToString()
Exit For
Case 9
str2 =ds.Tables(0).Rows(e.Row.RowIndex)("bet365_awin").ToString()
Exit For
End Select
If str1 <> str2 Then
Dim N1 As Double = Double.Parse(str1)
Dim N2 As Double = Double.Parse(str2)
If N1 <> N2 Then
If N1 > N2 Then
e.Row.Cells(i).BackColor = System.Drawing.Color.DarkSeaGreen
Else
e.Row.Cells(i).BackColor = System.Drawing.Color.Pink
End If
End If
End If
End If
Next
End If
End Sub