如何使用 C# 从网页中的 gridview 控件获取文本框值

how to get textbox value from a gridview control in a webpage using C#

我尝试使用以下代码从 gridview 中的文本框中获取值,但文本值显示为空白“”。

这段代码有什么问题?? TextBox box1 = (TextBox)grdCountry.Rows[rowIndex].Cells[0].FindControl("TextBox1");

设计代码:
<asp:gridview ID="grdCountry" runat="server" ShowFooter="true" AutoGenerateColumns="false"> <Columns> <asp:BoundField DataField="CountryName" HeaderText="Country" ItemStyle-Width="200px" /> <asp:TemplateField> <ItemTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>

尝试为文本框定义一个名称,并在 c# 中使用 "nameTextBox.Text();"

问题是 resolved.The 以上代码有效 properly.I 正在刷新整个页面,因此存储在文本框中的数据显示空白数据。