您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> .NET >> 在GridView中要使成绩一列小于60字体显示红色时出错

在GridView中要使成绩一列小于60字体显示红色时出错

来源:网络整理     时间:2016/6/22 4:30:10     关键词:

关于网友提出的“ 在GridView中要使成绩一列小于60字体显示红色时出错”问题疑问,本网通过在网上对“ 在GridView中要使成绩一列小于60字体显示红色时出错”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 在GridView中要使成绩一列小于60字体显示红色时出错
描述:

 代码如下:
   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:

    
    

            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;
            }
        }
    }

复制可用 解决方案2:

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;
  } 
  }

以上介绍了“ 在GridView中要使成绩一列小于60字体显示红色时出错”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1943308.html

相关图片

相关文章