Also, do you have a pager active? You are not filtering out that item type. I find it easier to do something like this (please excuse incorrect syntax, doing this from memory):
Code:
switch(e.Item.ItemType){
case ListItemType.Item:
case ListItemType.AlternateItem:
//do work here
break;
}
Regarding getting at the control itself, I find it less problematic to use the ID of the control. So inside the item template you have a control:
Code:
<asp:button runat="server" id="btnMyButton" />
Then in your codebehind:
Code:
Button myButton = (Button)e.Item.FindControl("btnMyButton");
This will find the button anywhere in the item, regardless of cell. This greatly reduces bugs and maintenance issues if you want to move things around.
-Peter
peterlanoie.blog