Hi Lars:
Let's say you have the following control inside of a DataGrid
TemplateColumn:
<asp:CheckBox Runat="server" ID="MyCheckBox"
OnCheckedChanged="MyCheckBox_CheckChanged" AutoPostBack="True"/>
You can write an event handler to get the index like so:
protected void MyCheckBox_CheckChanged(object source, EventArgs e)
{
Control c = (Control)source;
DataGridItem item = (DataGridItem)c.Parent.Parent;
Response.Write(item.ItemIndex);
}
Notice you need to go to the parent of the parent of the check box
control. You can see this if you dump the control hierarchy:
MyCheckBox (System.Web.UI.WebControls.CheckBox) ->
(System.Web.UI.WebControls.TableCell) ->
(System.Web.UI.WebControls.DataGridItem) ->
(System.Web.UI.WebControls.DataGridTable) ->
DataGrid1 (System.Web.UI.WebControls.DataGrid) ->
Form1 (System.Web.UI.HtmlControls.HtmlForm) ->
(ASP.FindControl4pre_aspx)
The CheckBox belongs to a TableCell control, which belongs to a
DataGridItem control, etc. etc. I have code to dump the hierarchy in
the following article:
http://odetocode.com/Articles/116.aspx
HTH,