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();

Recommended Answers

All 8 Replies

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\

what is GridView1? isn't it datagridview?

it is a gridview

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; 
    }
}

hey thank u dear... :)

U are welcome

Bold Text Here

Be a part of the DaniWeb community

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