Click here to Skip to main content
16,006,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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+"'))
               {

               }

           }
       }

   }



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
Posted

For changing color of row syntax is

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


Sorry ,if i got u wrong..
 
Share this answer
 
v2
Hi ,
Check this
C#
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;
            }
        }
    }

Best Regards
M.Mitwalli
 
Share this answer
 
C#
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;


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

C#
dataGridView1.Rows[2].DefaultCellStyle.BackColor = Color.Yellow;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900