gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:17:45 25 4
gpt4 key购买 nike

有人能告诉我如何在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com