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();
        mydataview = ds.Tables[0].DefaultView;
        if (sortExp != string.Empty)
            mydataview.Sort = string.Format("{0} {1}", sortExp, sortDir);
        GridView1.DataSource = mydataview;
5 Years
Discussion Span
Last Post by A0110

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" >
//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 by abelLazm: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.