how are you doing it? if it is in ItemCommand, tryvoid DataGrid_ItemCommand(Object sender, DataGridCommandEventArgs e)
{
Button btn = (Button)e.CommandSource;
TableCell tc = (TableCell)btn.Parent;
DataGridItem dgi = (DataGridItem)tc.Parent;
int i = dgi.Cells.GetCellIndex(tc);
}
{
Button btn = (Button)e.CommandSource;
TableCell tc = (TableCell)btn.Parent;
DataGridItem dgi = (DataGridItem)tc.Parent;
int i = dgi.Cells.GetCellIndex(tc);
}
Columns>
<asp:EditCommandColumn EditText="编辑" CancelText="取消" UpdateText="更新" ItemStyle-Wrap="false" />
</olumns>
通过使用EditCommandColumn 就可以对该列进行编辑
switch(((LinkButton)e.CommandSource).CommandName)
{ case "Delete":
DeleteItem(e);
break; // Add other cases here, if there are multiple ButtonColumns in
// the DataGrid control. default:
// Do nothing.
break;