首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-06-19 
在GridView中要使成绩一列小于60字体显示红色时出错代码如下:protected void GridView1_RowDataBound(obje

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

提示输入字符串出错。


[解决办法]
e.Row.Cells[6].Text.Trim()是整型的字符串嘛?
看看e.Row.Cells[6].Text.Trim()值是什么?

C# code
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;  }   }
[解决办法]
HTML code
    <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> 

热点排行