代码如下:
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;
}
}提示输入字符串出错。
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;
}
}提示输入字符串出错。
解决方案 »
- VS2003开发的网站经常出现Server unavailable的问题,如果将版本升级为高版本的VS,是否会有效果
- 对象实例化的问题
- petshop3里为什么我打的断点没有作用?
- datagrid 中添加选择列后转成摸板列的电击问题(内详)
- DropDownList报错
- 数据库类型中有小数位,类型只能设置成float????
- window 2003 不能安装 sql server 2000 不知为何?求各位指点!
- 紧急求救!
- 正在学asp.net 请大家推荐几个小点的web项目的例子(有源代码可以学习的),要小点的
- 关于session的权限实时问题
- 新增实体时,为什么主键ID是0?
- 请问.net中如何实现java中的这种数组类型?
看看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;
}
}
{
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;
}
}
}
<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;
}
}
}
复制可用