Strange Cell Formatting behaviour

Hi All,

I am trying to format some cells in the grid and have been experiencing strange behaviour.

If I try to set one cell to blue background, every second cell is being formatted.

WebWorksheet sheet = ContractsWebGrid1.WebWorksheets[0];

sheet.Cells[5, 5].Style.BackColor = System.Drawing.Color.Blue;

Here I am hard coding the cell to the row 5 col 5 but still every second cell is being changed to blue.

This has worked on other pages and I cant for the life of me work out what is going on.

Originally I wanted to put a BG color in every fourth row and did so with a loop through the rows and cells to set the back color. This ended up formating every second row instead of four. Some other issues also occured that didn't match what I was telling it to do. Like I bold the fourth row and set the other 3 rows to white text color to hide it, but it set all four rows to white.

Any assistance would be greatly appriciated.


Hi Rod,

I think you have implemented databinding. Well, in databinding mode, all the cells in a column will share one style object. This behavior actually reduces / minimizes the style object instances and improves the overall performance. If you want set a unique style for a particular cell in sheet in databinding mode, you should create a standalone style object for that cell.


After you call the sheet.DataBind() method, you may add the following lines of code:

// Bind the sheet to the dataset.
WebCell cell1 = sheet.Cells[5, 5];
// create a new style object
Aspose.Grid.Web.TableItemStyle style1 = new Aspose.Grid.Web.TableItemStyle();
// copy from the cell's style
style1.BackColor = Color.Blue;
cell1.Style = style1;

Thank you.

Thanks Amjad, I’ll give that a go.

Thanks again Amjad, using specific styles has fixed the problem

Hi Amjad,

How can I apply the style to subsequent pages.


Hi Rod,

Could you elaborate what do you mean by subsequent pages. If you have implemented and enabled paging in databinding mode, the technique is pretty same (for formatting a cell) as I described in my previous post, so you may refer to it. And, if you want to apply the style to all the pages cells, you should utilize GridWeb's Worksheet Editor to browse the BindColumns collection and then specify the Style / Alternative Style attributes of the columns data for your need.

And, if you are utilizing GridWeb's heirachical view in databinding mode and you have added and bound different sets of datatables (the source tables are associated with each other) to fill the dataset, you may handle GridWeb_BindingChildView event for your need. e.g..,

Suppose you have implemented GridWeb's heirarchical view and bound two/three datatables, now you want to specify some style attributes for the UnitPrice column cells in Order Details table, so, that when you click the "+" node to get the related data in other table(s), you want to have this data formatted.

Sample code:

// Handles the BindingChildView event to set the UnitPrice column.
protected void GridWeb1_BindingChildView(Aspose.Grid.Web.GridWeb childGrid, Aspose.Grid.Web.Data.WebWorksheet childSheet)
DataView view = (DataView)childSheet.DataSource;
if (view.Table.TableName == "Order Details")

childSheet.BindColumns["UnitPrice"].NumberType = NumberType.Currency3;
childSheet.BindColumns["UnitPrice"].Style.BackColor = System.Drawing.Color.Yellow;
//Use the following line if you don't want to implement the alternative style

childSheet.BindColumns["UnitPrice"].UseAlternativeStyle = false;


For further reference, please check the demo:

Thank you.

HI Amjad,

Yes, my mistake, I had stopped formatting at the page record length as I expected it to not allow me to format records that are not visible.

It appears to be working fine now, thanks for you help.