Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column number from Itemdatabound help

Status
Not open for further replies.

Lbob

Programmer
May 23, 2003
157
GB
Hi

I want to alternate the color of the cells by column rather than row, but this depends on the content of the cell.

How do I reference the column in the itemdatabound? This is what I've got so far...

If e.Item.Cells(i).Text = "Empty" Then

'If column is even then use css Even, else use css odd

end if

Cheers
Lbob
 
Code:
If  e.Item.Cells(i).Text = "Empty"
   e.Item.Cells(i).CssClass = "Even"
Else
   e.Item.Cells(i).CssClass = "Odd"
End If
OR
Code:
With e.Item.Cells(i)
   If .Text = "Empty" Then
      .CssClass = "Even"
   Else
      .CssClass = "Odd"
   End If
End With
 
How about this?

Code:
bool isOddCell = false;
for (int i = 0; i < e.Item.Cells.Count; i++)
{
	isOddCell = !isOddCell;
	if (e.Item.Cells[i].Text == "Empty")
	{
		if (isOddCell) e.Item.CssClass = "odd";
		else e.Item.CssClass = "even";
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top