我想這樣的事情,但沒有奏效:如何在GridView RowCommand事件中查找控件?
GridViewRow row = (GridViewRow)(((Repeater)e.CommandSource).NamingContainer);
Repeater _rpt1 = row.Cells[8].FindControl("rptReg") as Repeater;
錯誤:
Unable to cast object of type 'System.Web.UI.WebControls.Button' to type 'System.Web.UI.WebControls.Repeater'.
是有辦法,我可以使用的GridView中OnRowCommand
事件下面的代碼?
其實我試圖從GridView控件刪除該行並在其上的用戶點擊,我抓住了多張標識和傳遞給SP和更新表和databind the gridview
GridViewRow row = gv.SelectedRow;
Repeater _rpt = gv.Rows[e.RowIndex].Cells[8].FindControl("rptReg") as Repeater;
Repeater _rpt1 = gv.Rows[e.RowIndex].Cells[9].FindControl("rptVisitor") as Repeater;
foreach (RepeaterItem item in _rpt.Items)
{
TextBox _txt = item.FindControl("txtId") as TextBox;
TextBox _txt1 = item.FindControl("txtName") as TextBox;
//update db
}
我不知道我按照但在OnRowCommand你可以檢查e.CommandName ==「刪除」 – Malk 2011-01-31 22:32:00
多數民衆贊成在正確的,但我有一種情況,我正在尋找一種方式來做RowCommand的FindControl? – 2011-01-31 22:33:17