适用
ImageButton
LinkButton
//Gridview 
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
        try
        {
            int rowindex = ((GridViewRow)(((ImageButton)sender).NamingContainer)).RowIndex;
            string id = GridView1.DataKeys[rowindex].Value.ToString();
    ............
        }
        catch(Exception ex)
        {
            throw ex;
        }
}
//Datalist
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
        try
        {
            int rowindex = ((DataListItem)(((ImageButton)sender).NamingContainer)).RowIndex;
            string id = DataList1.DataKeys[rowindex].Value.ToString();
    ............
        }
        catch(Exception ex)
        {
            throw ex;
        }
}