2

I want to change a particular row color of gridview based on some condition, i am using ASP.NET with c#.

I know i can use the HTMLCellPrepared method, but in my method i want to look at the values of other grids as well? Is this possible?

    protected void GVResults_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
    {
        if (e.DataColumn.FieldName == "CarrierId")
            if ( Convert.ToInt32(e.CellValue) > 0)
                e.Cell.ForeColor = System.Drawing.Color.Red;            
    }

This is the first part of the method, but i want to look at values from other grids in order to make visual changes to this grid. Problem is I dont know how to access values from other grids....

jeffry
  • 327
  • 2
  • 8
  • 23
  • Yes it's possible however your question is too high level. Please elaborate on `some condition` and include any code you already have – DGibbs Dec 19 '13 at 09:52
  • @DGibbs The condition is going to be based on values from another ASPXGridView and values from 2 drop down lists. Its a bit complex but I just need to figure out how to access values from a different ASPXGridview – jeffry Dec 19 '13 at 10:11

2 Answers2

4

I would recommend you to use the htmlrowprepared event for the conditional coloring of row.

According to the code you have written, below example can help you :

protected void GVResults_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType != GridViewRowType.Data) return;
        int value = (int)e.GetValue("CarrierId");
        if (value > 0)
            e.Row.ForeColor = System.Drawing.Color.Red;
    }

Reference:
Changing ASPxGridView Cell and Row Color on Condition

Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
Ruchi
  • 1,238
  • 11
  • 32
1

You can use RowDataBound event of GridView to check a condition if your styling depends on data and set a style for that condition.

Here is an example of this.

Semih Yagcioglu
  • 4,011
  • 1
  • 26
  • 43