hi all,

I have a asp page. In that i am displaying some data in a grid view from database.In grid view i am displaying TicketNo,TicketName and status. Now my problem is that when page loads if the status have a value as 'OPEN' that row should be in red color.(My intension is when we look at that gridview we should easily trace the new ticket(Open))
here is my gridview code.

Sql = new SqlDataAdapter("Select * from view_Ticket order by TicketNo desc", con); 
        DataSet ds = new DataSet();
        Sql.Fill(ds);
        
        mydataview = ds.Tables[0].DefaultView;
        if (sortExp != string.Empty)
        {
            mydataview.Sort = string.Format("{0} {1}", sortExp, sortDir);
        }
        GridView1.DataSource = mydataview;
        GridView1.DataBind();

Check this code

foreach (DataGridViewRow dgvr in GridView1.Rows)
{
  if (dgvr.Cells["status"].Value.ToString()=="Open")
  {
    dgvr.DefaultCellStyle.ForeColor = Color.Red;
  }
}

i have put that code but i am getting error as

Error 4 The type or namespace name 'DataGridViewRow' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Invensis\My Documents\Visual Studio 2008\websites\WebSite3\Admin.aspx.cs 91 18 C:\...\WebSite3\

Try adding this event in you code

//if you are working in asp
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" >
...
</asp:GridView>
//if you are working in c#
this.GridView1.OnRowDataBound+=new  GridViewRowEventHnadler(GridView1_RowDataBound);
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    // searching through the rows
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       String status = DataBinder.Eval(e.Row.DataItem, "status").ToString();

        if (status.ToUpper()=="OPEN" ) 
       e.Row.BackColor = Color.Red; 
    }
}

Edited 5 Years Ago by abelLazm: n/a

This question has already been answered. Start a new discussion instead.