ItemDataBound event woes...

  • Thread starter Thread starter Roy
  • Start date Start date
R

Roy

Hey all,
This is a fairly broad question, but why is it that my datagrid hits
the ItemDataBound event 3 times?

Basically, I placed a response.write in all sub and functions in my
codebehind and discovered that my page_load,prerender,and binddata subs
all get called once, but my itemdatabound event gets called 3 times.
What's weird is that there is only 1 row being pushed into the
datagrid, so I should only be seeing one itemdatabound call, right?
Certainly not 3...

On a hunch, I'm thinking that somehow the 3 calls represent the
datagrid header, content, and footer... Am I misunderstanding this?
 
Hi Roy,

In ItemDataBound event all items (including ListItemType.Item,
ListItemType.Header, and ListItemType.Footer) are processed. In order to
avoid process header and Footer, you can code like

if (e.Item.ItemType == ListItemType.Item || ListItemType.Item ==
ListItemType.AlternatingItem)
{
// process
}

HTH

Elton Wang
(e-mail address removed)
 
Back
Top