我已经在VS2015中将一个正在运行的VB项目从VS2010转换为C#,但是现在到Int / decimal的字符串不再有效......而且我的生活中找不到原因。
问题是当页面加载RowDataBound触发器(正常工作)但我有if
触发器根据值突出显示单元格,但它们似乎不起作用..
所以你可以从下面的代码中看到,我已经尝试了十进制(所有值都返回0,所以没有触发器发生),我已经尝试过int32所有触发器仍然显示为0,所以我认为它之间的转换SQL数据和转换为int。
我在我的智慧中的任何想法都会在此结束:(。
p.s数据必须有小数位,但需要比较为If值大于45或者值是40到45(或44.999999999)
-EDIT-
下面的代码显示了我尝试过的两种类型的代码(都失败了),问题是将e.Row.Cells[y].Text
部分转换为可用的decimal / int函数。
- 结束编辑 -
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
string testValue = e.Row.Cells[3].Text;
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Visible = false;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int d = 3; d <= 22; d++)
{
e.Row.Cells[d + 1].Visible = false;
e.Row.Cells[d].ToolTip = e.Row.Cells[d + 1].Text;
d = d + 1;
}
e.Row.Cells[0].Visible = false;
for (int y = 3; y <= 22; y++)
{
Decimal testval;
if (string.IsNullOrWhiteSpace(e.Row.Cells[y].Text))
return;
Decimal.TryParse(e.Row.Cells[y].Text,out testval);
int n = Convert.ToInt32(testval);
if (n > 44.999999)
{
if (testval < 45)
{
e.Row.Cells[y].Attributes.Add("Style", "background-color: orange;");
e.Row.Cells[y].ForeColor = Color.Black;
}
}
if (testval > 44.9999999999999)
{
e.Row.Cells[y].Attributes.Add("Style", "background-color: red;");
e.Row.Cells[y].ForeColor = Color.Black;
}
y = y + 1;
if (testval > 0)
{
e.Row.Cells[23].Attributes.Add("Style", "background-color: red;");
e.Row.Cells[23].ForeColor = Color.Black;
}
}
for (int x = 3; x <= 22; x++)
{
int testval1;
int.TryParse(e.Row.Cells[x].Text, out testval1);
if (testval1 == 0)
{
e.Row.Cells[x].Text = "Rest";
}
x = x + 1;
}
}
}
答案 0 :(得分:0)
问题是VS2015仍然以testval
作为int,即使它被改为十进制,一个干净/重建修复了这个问题。