【ASP.NET】GridView在RowCommand中FindControl

GridView在RowCommand中FindControl

老是記不住!!

在這裡做個紀錄!以後就快多了!!

protected void gvAssign_RowCommand(object sender, GridViewCommandEventArgs e)
{
    GridViewRow row = ((Button)e.CommandSource).Parent.Parent as GridViewRow;
    switch (e.CommandName)
    {
        case "GoAssign":
            HiddenField HiddenUnitID = (HiddenField)row.Cells[2].FindControl("HiddenUnitID");
            Response.Write(HiddenUnitID.Value);
            break;
    }
}