c# - ASP.NET Gridview 的编辑文本框

标签 c# asp.net gridview

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

最佳答案

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

在你的gridview的rowedit事件中是

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


  }

关于c# - ASP.NET Gridview 的编辑文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6206370/

相关文章:

asp.net - 获取排序列表中的最大键

c# - 在 UWP 的 gridview 中检索 JSON 数据

c# - 使用 C# 检查 gridview 是否为空

c# - 如何为 C# Windows 应用程序创建自动更新

c# - T4 抑制错误消息 "ErrorGeneratingOutput"

c# - 如何在不损失质量的情况下将 jpeg 转换为字节数组

c# - 将 Access 报告导出为 PDF

asp.net - 如何使安全 token 在被动 STS 设置中自动过期?

c# - C# GridView 中的 DateTime 更新字段

c# - 如何通过 jQuery 上传文件?