2011-09-23 78 views
1

我有一個名爲「UpdateAll」的gridview外部的按鈕,我需要能夠點擊這樣的按鈕並找到一個項目模板「DropDownList」並使用該值爲每個記錄更新數據庫,我不確定如何去解決這個問題?從非GridView事件訪問gridview

public void UpdateAll_Click(object sender, EventArgs e) 
{ 

} 

現在我知道我可以向下進入下降的GridView_RowCommand像這樣

GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer); 
     Myddl = row.FindControl("Quantity") as DropDownList; 

,但我不知道怎麼做,從沒有GridView的關係,我可以在外線活動不做以上的一個,因爲它訪問e.CommandSource.

請幫助。

回答

1

你可以這樣做;

for(int rowIndex =0; rowIndex<gv.rows.count; rowIndex++) 
{ 
    Myddl = gv.rows[rowIndex].FindControl("Quantity") as DropDownList; 

}