for (int i = 0; i < GridView1.Rows.Count; i++)
{
string i1 = e.Row.Cells[0].Text;
string i2 = e.Row.Cells[1].Text;
string i3 = e.Row.Cells[2].Text;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[6].Text == "2008-5-17")
{
e.Row.Cells[4].ForeColor= System.Drawing.Color.Green;
}
}
}
断点测试e.Row.Cells[6].Text 取不到值,为空, 让后前边加了:
string i1 = e.Row.Cells[0].Text;
string i2 = e.Row.Cells[1].Text;
string i3 = e.Row.Cells[2].Text;
就提示指定的参数已超出有效值的范围。
要取的是模板列的值
{
string i1 = e.Row.Cells[0].Text;
string i2 = e.Row.Cells[1].Text;
string i3 = e.Row.Cells[2].Text;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[6].Text == "2008-5-17")
{
e.Row.Cells[4].ForeColor= System.Drawing.Color.Green;
}
}
}
断点测试e.Row.Cells[6].Text 取不到值,为空, 让后前边加了:
string i1 = e.Row.Cells[0].Text;
string i2 = e.Row.Cells[1].Text;
string i3 = e.Row.Cells[2].Text;
就提示指定的参数已超出有效值的范围。
要取的是模板列的值
if(t != null)
{
string str = t.Text;
}
if(t != null)
{
string str=t.Text.Substring(0,9);
for (int i = 0; i < GridView1.Rows.Count; i++)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
if (str== "2008-5-17")
{
e.Row.Cells[4].ForeColor= System.Drawing.Color.Green;
}
}
}
}
第一行加断点调试没问题 能取到值了。 可把断点取掉 运行的时候 第一行有错 指定的参数已超出有效值的范围
if(lbl != null) {
// lbl.Text
// ...
}