C# ASP.NET Gridview';编辑文本框

C# ASP.NET Gridview';编辑文本框,c#,asp.net,gridview,C#,Asp.net,Gridview,有人能告诉我如何在asp.net c#中检索gridview中的文本框吗?我有一堆数据显示在gridview中,我希望它是可编辑的。我已经添加了一个编辑命令字段,它给了我这个编辑链接。当我按下此链接时,会出现一个文本框,但我如何获取该文本框的引用,以便在调用行更新处理程序之前获取文本框中的任何内容并对其进行更改?使用FindControl方法查找所需的文本框 在您的rowedit中,gridview的事件是 void AuthorsGridView_RowUpdating (Object sen

有人能告诉我如何在asp.net c#中检索gridview中的文本框吗?我有一堆数据显示在gridview中,我希望它是可编辑的。我已经添加了一个编辑命令字段,它给了我这个编辑链接。当我按下此链接时,会出现一个文本框,但我如何获取该文本框的引用,以便在调用行更新处理程序之前获取文本框中的任何内容并对其进行更改?

使用
FindControl
方法查找所需的文本框

在您的rowedit中,gridview的事件是

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");


  }

您可以通过知道元素位于
RowIndex
中的行以及元素名称
“text\u textbox”


如果答案对你有用,别忘了把它标为“接受”
TextBox text = ((TextBox)contacts.Rows[RowIndex].FindControl("text_textbox")).Text;