這個範例會用.FindControl()方法,抓取到GridView按下編輯更新資料之後的值。

 

重點:

1.如果是搭配SqlDataSource 記得設定DataKeysName,因為這個範例要抓取到id。

2.GridView按下編輯更新觸發的事件是: GridView_RowUpdating()。

3.使用者點選的那一列是用: GridView.Rows[e.RowIndex] 抓取到的。

 

後置程式碼如下:

//GridView按下編輯更新觸發的事件是: GridView_RowUpdating()
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//抓取GridView的id
Response.Write("顯示id" + GridView1.DataKeys[e.RowIndex].Value.ToString());

TextBox TB = new TextBox();

//抓取樣板中的子控制項,有一個TextBox2的ID:TextBox2,可以查看前端程式碼得知
TB = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2");
Response.Write(TB.Text);
Response.End();
}

 

 

文章標籤
全站熱搜
創作者介紹
創作者 melomelo1988 的頭像
melomelo1988

melo 唐

melomelo1988 發表在 痞客邦 留言(0) 人氣(1,948)