Monday, July 03, 2006

DataList ItemIndex and GridView DataItemIndex

I've been messing with things in .NET2 and found the following...

Inside a DataList you can do this:

< % # Container.ItemIndex % >
Which databinds the current item's index to whatever so it can affect the rendered output
(why else would you do it, d'oh!)

But in GridView you have to do this:

< % # Container.DataItemIndex % >
For example, I have a datalist in which I want to have a thick border around only the first item (an image and some text) in order to make it obvious that that is the main image in the gallery

I use:

< border =" '" itemindex ="="">
' >

But in a grid view, where i want a label in the first column of only the first row, I use:

< runat="server" id="Label1" text="Main" visible="'" dataitemindex ="=""> '
/ >

1 comment: