有两列gridview,一个有值,另一个会每个月都有。我想使用条件运算符(>或<)来比较两列。 我使用了下面的代码,但它不起作用。如何在c的gridview列中使用条件运算符#
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string Threshold = e.Row.Cells[3].Text;
int result = int.Parse(Threshold.Replace("%", ""));
int ThreCol;
int ResCol;
ThreCol = int.Parse(e.Row.Cells[3].Text);
ResCol = int.Parse(e.Row.Cells[4].Text);
if (e.Row.Cells[4].Text == result.ToString().Trim())
{
e.Row.Cells[4].BackColor = Color.MediumSeaGreen;
}
if (ResCol > ThreCol)
{
e.Row.Cells[4].BackColor = Color.Yellow;
}
else
{
e.Row.Cells[4].BackColor = Color.LightCoral;
}
}
}
错误
输入字符串的不正确的格式。
看看错误发生的路线。然后再次读取错误信息:'输入字符串格式不正确。您试图将字符串解析为整数,但字符串无效。 – Rob
解决方案是使用调试器,找出哪条线路坏了,查看字符串,并找出字符串为什么不是数字,或者为什么你认为它是一个数字。 SO不是调试服务。 – Rob
请显示您的Gridview – fubo