2 回答

TA貢獻1848條經驗 獲得超10個贊
要想?RowDataBound時間找到?EditItemTemplate里的控件,必須點擊編輯按鈕執行??
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
??????? {
??????????? GridView1.EditIndex = e.NewEditIndex;
??????????? LoadData();//此時綁定數據源時?RowDataBound事件函數能找到你的控件。
??????????? }
?private void LoadData()
??????? {
??????????? GridView1.DataSource = GridViewClass.ReadData();
??????????? GridView1.DataBind();
??????? }
??????? protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
??????? {
??????????? GridView1.EditIndex = -1;
??????????? LoadData();
??????? }
??????? protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
??????? {
??????????? if (e.Row.RowType == DataControlRowType.DataRow)
??????????? {
????????????? //要想找到控件必須點擊EDIT按鈕重新綁定DataSource
???????????? ? TextBox txt = (TextBox)e.Row.FindControl("TextBox1");
??????????????? if (txt != null)
??????????????? {
??????????????????? txt.Text ="ggggg";
??????????????? }
??????????? }
??????? }
- 2 回答
- 0 關注
- 1053 瀏覽
添加回答
舉報