0
找到控件(例如標籤,圖像)後,我想查找與所有控件關聯的文本值,並最終將該文本值分配給文本框。如何找到GridView的OnRowEditing事件和與控件相關的文本的控件?
找到控件(例如標籤,圖像)後,我想查找與所有控件關聯的文本值,並最終將該文本值分配給文本框。如何找到GridView的OnRowEditing事件和與控件相關的文本的控件?
試試這個onRowEditing
事件
GridViewRow row = MyGrid.Rows[e.RowIndex];
Label MyLabel = (Label)row.FindControl("MyLabel");
的lableText
值指定到你想要的文本框。
更新1:
DataRow row = ((DataRowView)e.Row.DataItem).Row;
Label Mylabel = (Label)e.Row.FindControl("MyLabel");
MyLable
是您定義爲您的GridView .aspx頁面中
上爲行編輯和更新,你可以使用這個控件ID ...
protected void grdemployee_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int id = Int32.Parse(grdemployee.DataKeys[e.RowIndex].Value.ToString());
TextBox txtname = (TextBox)grdemployee.Rows[e.RowIndex].FindControl("txtname");
grdemployee.EditIndex = -1; BindGridview();
}
未將對象引用設置爲對象的實例。錯誤發生 – svs