代码如下:
   protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {  
            if (Convert.ToInt32(e.Row.Cells[6].Text.Trim()) <= 0
                  || Convert.ToInt32(e.Row.Cells[6].Text.Trim()) > 60)
            {
                e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;
            } 
        }提示输入字符串出错。

解决方案 »

  1.   

    e.Row.Cells[6].Text.Trim()是整型的字符串嘛?
    看看e.Row.Cells[6].Text.Trim()值是什么?protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
      string test=e.Row.Cells[6].Text.Trim();//看看这里的值是什么?
      if (e.Row.RowType == DataControlRowType.DataRow)
      {  
      if (Convert.ToInt32(e.Row.Cells[6].Text.Trim()) <= 0
      || Convert.ToInt32(e.Row.Cells[6].Text.Trim()) < 60)
      {
      e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;
      } 
      }
      

  2.   

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string grade = e.Row.Cells[6].Text.Trim();
                if (!string.IsNullOrEmpty(grade) && Convert.ToInt32(grade) < 60)
                {
                    e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;
                }
            }
        }
      

  3.   

    肯定cell的内容没办法转为Convert.ToInt32,所以你要进行一下判断
      

  4.   

    那个e.Row.Cells[6]指的是第六列是吗,因为之前都没有用过这个,用了你们的方法打了断点调试,发现它的值是空的。
      

  5.   

    e.Row.Cells[6]指的是本行的第七个单元格,如果是第六个单元格是e.Row.Cells[5]
      

  6.   

    他总是提示e.Row.Cells[6].Text.Trim()的值为空,数据库里面用的是numeric(5, 2),那我该怎样取出GridView里成绩的值,然后把小于60的字体设置成红色呢,我是在VS2010下做的。
      

  7.   

        <form id="form1" runat="server">
        <div>
            <asp:GridView ID="gv" runat="server" AutoGenerateColumns="false" onrowdatabound="gv_RowDataBound">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Label ID="lblGrade" runat="server" Text='<%#Eval("Grade") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            </asp:GridView>
        </div>
        </form>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrade();
            }
        }    protected void BindGrade()
        {
            var list = new[]{ 
                new{Grade=30},
                new{Grade=52},
                new{Grade=55},
                new{Grade=75},
                new{Grade=60},
                new{Grade=80},
                new{Grade=50}
            }.ToList();
            gv.DataSource = list;
            gv.DataBind();
        }
        protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblGrade = e.Row.FindControl("lblGrade") as Label;
                int grade = Convert.ToInt32(lblGrade.Text);
                if (grade < 60)
                {
                    lblGrade.ForeColor = System.Drawing.Color.Red;
                }
            }
        }
    复制可用
      

  8.   

    你能确保这一列一定有数据吗?用convert转换如果是空的会报错。数字转换建议用int.TryPrase
      

  9.   

    你用js或者jquery写个方法,之后在前台调,试一下。
      

  10.   

    FindControl 通过找到控件 然后再进行判断
      

  11.   

    licai1210写的很好嘛。完全可以的。