如果满足特定条件,如何更改网格视图的行颜色或突出显示行 [英] How to change the row color of grid view or highlight the row if it meet certain condition

查看:138
本文介绍了如果满足特定条件,如何更改网格视图的行颜色或突出显示行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void GvLpDpDetail_RowDataBound1(object sender, GridViewRowEventArgs e)
   {

       objdb = new DB();
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           string StrQ = "select  DP.Ref_No,DP.Category_Name,DP.Appointed_By1,DP.Total_Qty,DP.DP1_Name,DP.DP1_SailingDate,LP.Vessel_Name,LP.Total_Lp_Qty,LP.LP1_Name,LP.Load_Sailing from Discharge_Port as DP inner join Load_Port as LP on DP.Ref_No =LP.Ref_No  where DATEDIFF(Day,DP.ETA,GETDATE())>'12'  and DP.DP1_ArrivalDate is  null";
           ds = objdb.getdata(StrQ);

           GvLpDpDetail.DataSource = ds;
           GvLpDpDetail.DataBind();
           DataRowView drv=(DataRowView)e.Row.DataItem;
           for (int i = 0; i < drv.DataView.Table.Columns.Count;i++ )
           {
               e.Row.ForeColor = System.Drawing.Color.Red;
               if((int)DataBinder.Eval(e.Row.DataItem,'"+ds+"'))
               {

               }

           }
       }

   }




我有一个网格,该网格显示两个表中的值,并且在网格的select事件上,它基于参考号显示其他详细信息.

但是知道我想根据上述条件改变行的颜色,我正在尝试网格视图的RowDataBound事件,但是我做不到,有人可以告诉我如何获得所需的结果. >
或实现上述条件的任何建议或代码步骤.
还是做错了,请告诉我

在此先感谢




I have a grid which display value from two table and on the select event of the grid it display the other details based on the reference number.

But know i want to change the color of the row high light the row on the basis of above condition i am trying on RowDataBound event of grid view but i cant do this can some one tell me how to get the desired result.

or any advice or code step to achieve the above condition .
or am doing it wrong please tell me

Thanks in advance

推荐答案

更改行语法的颜色是

For changing color of row syntax is

Datagridview.row[0].DefaultCellStyle.color = color.Blue;



抱歉,如果我弄错了.



Sorry ,if i got u wrong..



检查此
Hi ,
Check this
GridView1.Rows[1].Cells[1].BackColor = System.Drawing.Color.Red;

 protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow )
        {
            if (e.Row.Cells[1].Text == "1")
            {
                e.Row.Cells[1].BackColor = Color.Red;
            }
        }
    }


最好的问候
M.Mitwalli


Best Regards
M.Mitwalli


dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;



使用此代码聚焦特定行,然后使用
突出显示或更改颜色



use this code to focus a specific row and then highlight or change the color using

dataGridView1.Rows[2].DefaultCellStyle.BackColor = Color.Yellow;


这篇关于如果满足特定条件,如何更改网格视图的行颜色或突出显示行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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