摘要:抓EditItemTemplate內的DropDownList值
要抓EditItemTemplate內的DropDownList值時,發生的錯誤訊息如下:
無法將型別 'System.Web.UI.WebControls.Button' 的物件轉換為型別 'System.Web.UI.WebControls.DropDownList'
原始碼:
DropDownList regionID;
regionID = (DropDownList)gvCheckerRegion.Rows[e.RowIndex].Cells[2].Controls[0];
解決方式:
改為
regionID = (DropDownList)gvCheckerRegion.Rows[e.RowIndex].FindControl("EditddlCityRegion");
才能正確的抓取DropDownList的值