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();
Re: Grid view row color 80 80

Check this code

foreach (DataGridViewRow dgvr in GridView1.Rows)
{
  if (dgvr.Cells["status"].Value.ToString()=="Open")
  {
    dgvr.DefaultCellStyle.ForeColor = Color.Red;
  }
}
Re: Grid view row color 80 80

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\

Re: Grid view row color 80 80

what is GridView1? isn't it datagridview?

Re: Grid view row color 80 80

it is a gridview

Re: Grid view row color 80 80

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; 
    }
}
Re: Grid view row color 80 80

hey thank u dear... :)

Re: Grid view row color 80 80

U are welcome

Re: Grid view row color 80 80

Bold Text Here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.