2011-06-01 81 views
2

有人能告訴我如何檢索asp.net c#中的gridview中的文本框嗎?我有一堆數據顯示在gridview中,我希望它是可編輯的。我已經添加了一個編輯命令字段,它給了我這個編輯鏈接。當我按下這個鏈接時,會出現一個文本框,但是我如何獲得該文本框的引用,以便可以在調用行更新處理程序之前獲取文本框內的任何內容並對其進行更改?在GridView中的你rowedit事件ASP.NET Gridview的編輯文本框

+0

不要忘記將答案標記爲接受, – 2011-06-01 19:23:11

回答

1

。利用FindControl的方法來找到你想要的文本框......

void AuthorsGridView_RowUpdating (Object sender, GridViewUpdateEventArgs e) 
    { 
    // The GridView control does not automatically extract updated values 
    // from TemplateField column fields. These values must be added manually 
    // to the NewValues dictionary. 

    // Get the GridViewRow object that represents the row being edited 
    // from the Rows collection of the GridView control. 
    int index = AuthorsGridView.EditIndex; 
    GridViewRow row = AuthorsGridView.Rows[index]; 

    // Get the controls that contain the updated values. In this 
    // example, the updated values are contained in the TextBox 
    // controls declared in the edit item templates of each TemplateField 
    // column fields in the GridView control. 
    TextBox lastName = (TextBox)row.FindControl("LastNameTextBox"); 
    TextBox firstName = (TextBox)row.FindControl("FirstNameTextBox"); 


    } 
0

您可以通過了解在GridView訪問一個元素它位於RowIndex之內並且元素名稱"text_textbox"

TextBox text = ((TextBox)contacts.Rows[RowIndex].FindControl("text_textbox")).Text;