一向用開類似依個既方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | protected void Button1_Click(object sender, EventArgs e) { // Iterates through the rows of the GridView control foreach (GridViewRow row in GridView1.Rows) { // Selects the text from the TextBox // which is inside the GridViewRow control string textBoxText = ((TextBox)row.FindControl("TextBox1")).Text; Response.Write(textBoxText); } } [/geshi] <p></p> <p>但而家唔再得, 因為個 control 唔再屬於 GridViewRow, 就我所見 GridViewRow 之下既 Control 變晒System.Web.UI.WebControls.DataControlFieldCell, 而 FindControl 唔會再 search 入去, 結果要再搵深多層:</p> [geshi lang=C] protected void Button1_Click(object sender, EventArgs e) { // Iterates through the rows of the GridView control foreach (GridViewRow row in GridView1.Rows) { foreach (Control ctrl in row.Controls) { // Selects the text from the TextBox // which is inside the DataControlFieldCell control of a GridViewRow string textBoxText = ((TextBox)ctrl.FindControl("TextBox1")).Text; Response.Write(textBoxText); } } } |