为gridview的特定行提供颜色. [英] giving a color to the particular row of the gridview.

查看:80
本文介绍了为gridview的特定行提供颜色.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个从数据库值绑定的gridview.
我只想在加载时更改网格视图中特定行的颜色.
例如:第三排的底色

谁能建议我,我该怎么做?

感谢和问候,

Hi All,

I have a gridview which is getting bound from the database values.
I just want to change the color of the particular row in my gridview when it loads.
ex: back color for 3rd row

Can any one please suggest me, how do I do that?

Thanks and Regards,

推荐答案


在geidview创建的事件中,您可以更改颜色

受保护的void GridView1_RowCreated(对象发送者,GridViewRowEventArgs e)
{
如果(e.Row.RowIndex == 2)
{
e.Row.BackColor = Color.Red;
}
}
Hi
In row created event of your geidview you can change the color

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex == 2)
{
e.Row.BackColor = Color.Red;
}
}


关于RowBound事件..

on RowBound event..

Protected void _GridView_RowBound(Object sender, GridViewCommandEventArgs e)
{
    GridViewRow gdvrow = e.Row;
    
    if (your condition)
    {
       gdvrow.BackColor = Drawing.Color.LightGreen;
    }
    else
    {
        gdvrow.BackColor = Drawing.Color.Pink;
    }
}



希望这对您有帮助...



Hope this helps...


您可以使用y客户端[无回发]或通过代码隐藏进行操作.

使用背后的代码:
在gridview的RowDataBound事件上使用此代码
You can do it using either y client side [without postback] or by codebehind.

using codebehind:
use this code on RowDataBound event of gridview
e.Row.BackColor = Drawing.Color.Yellow



使用Javascript:
单击时更改GridView行颜色而无回发 [



using Javascript:
Change the GridView row color on click without postback[^]


这篇关于为gridview的特定行提供颜色.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆