这是一个记录用户登录信息的GridView控件,我希望将“登录失败”的字样变成醒目的红色(其它登录正常的字颜色不变),请问应该在哪里设置?
11 个解决方案
#1
在后台的代码里就可以设置~
#2
行绑定事件:
if(...==)//如果是数据行
{
if(....Text=="失败")
{
//改变颜色
}
} 很久没写了 只记得大概
if(...==)//如果是数据行
{
if(....Text=="失败")
{
//改变颜色
}
} 很久没写了 只记得大概
#3
就是.cs文件里面加还是.aspx?
#4
GridView1.Rows[i].Cells[j].ForeColor = Color.red
#5
添加行数据绑定事件
如果使用的是模板
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
//判断是否为数据行(排除头部和底部)
if (row.RowType == DataControlRowType.DataRow)
{
//找到所在单元格,索引从0开始
if (row.Cells[1].Text == "登陆失败")
{
row.Cells[1].ForeColor = System.Drawing.Color.Red;
}
}
}
如果使用的是模板
//要先通过ID找到那个控件
Label lbl = row.Cells[1].FindControl("ID") as Label;
if (lbl.Text == "登陆失败")
{
lbl.ForeColor = System.Drawing.Color.Red;
}
#6
这个。。。/lh
#7
顶
#8
for (int i = 0; i < this.GridView1.Rows.Count;i++ )
{
Label lb = (Label)this.GridView1.FindControl("lable1") as Label;
if(lb.Text.Equals("登录失败"))
{
lb.ForeColor = System.Drawing.Color.Red;
}
}
不妨试试这个
{
Label lb = (Label)this.GridView1.FindControl("lable1") as Label;
if(lb.Text.Equals("登录失败"))
{
lb.ForeColor = System.Drawing.Color.Red;
}
}
不妨试试这个
#9
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text == "登录失败")
{
//e.Row.BackColor = System.Drawing.Color.Red;
e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
}
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text == "登录失败")
{
//e.Row.BackColor = System.Drawing.Color.Red;
e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
}
}
}
#10
顶
#11
5楼说的很详细,顶
#1
在后台的代码里就可以设置~
#2
行绑定事件:
if(...==)//如果是数据行
{
if(....Text=="失败")
{
//改变颜色
}
} 很久没写了 只记得大概
if(...==)//如果是数据行
{
if(....Text=="失败")
{
//改变颜色
}
} 很久没写了 只记得大概
#3
就是.cs文件里面加还是.aspx?
#4
GridView1.Rows[i].Cells[j].ForeColor = Color.red
#5
添加行数据绑定事件
如果使用的是模板
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
//判断是否为数据行(排除头部和底部)
if (row.RowType == DataControlRowType.DataRow)
{
//找到所在单元格,索引从0开始
if (row.Cells[1].Text == "登陆失败")
{
row.Cells[1].ForeColor = System.Drawing.Color.Red;
}
}
}
如果使用的是模板
//要先通过ID找到那个控件
Label lbl = row.Cells[1].FindControl("ID") as Label;
if (lbl.Text == "登陆失败")
{
lbl.ForeColor = System.Drawing.Color.Red;
}
#6
这个。。。/lh
#7
顶
#8
for (int i = 0; i < this.GridView1.Rows.Count;i++ )
{
Label lb = (Label)this.GridView1.FindControl("lable1") as Label;
if(lb.Text.Equals("登录失败"))
{
lb.ForeColor = System.Drawing.Color.Red;
}
}
不妨试试这个
{
Label lb = (Label)this.GridView1.FindControl("lable1") as Label;
if(lb.Text.Equals("登录失败"))
{
lb.ForeColor = System.Drawing.Color.Red;
}
}
不妨试试这个
#9
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text == "登录失败")
{
//e.Row.BackColor = System.Drawing.Color.Red;
e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
}
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text == "登录失败")
{
//e.Row.BackColor = System.Drawing.Color.Red;
e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
}
}
}
#10
顶
#11
5楼说的很详细,顶