更改Gridview中的文本框数据(asp net c#)

更改Gridview中的文本框数据(asp net c#),c#,asp.net,C#,Asp.net,我创建了一个gridview,其中包含在后端填充的文本框: <asp:GridView ID="grvMyTest" runat="server" AutoGenerateColumns="False" EnableModelValidation="True" Height="30%" TabIndex="9" AllowSorting="True" Width="100%" Visible="true" AllowPaging="True" PageSize="20" CssClas

我创建了一个gridview,其中包含在后端填充的文本框:

<asp:GridView ID="grvMyTest" runat="server" AutoGenerateColumns="False"
EnableModelValidation="True" Height="30%" TabIndex="9" 
AllowSorting="True" Width="100%" Visible="true" AllowPaging="True" 
PageSize="20" CssClass="mGrid" PagerStyle-CssClass="pgr">
  <Columns>
     <asp:TemplateField HeaderText="Jan">
        <ItemTemplate>
           <asp:TextBox ID="tbjan" runat="server" Text='<%# Eval("mJan") %>' 
              Width="50px" style="text-align: center"></asp:TextBox>
        </ItemTemplate>
      <HeaderStyle BackColor="Control" HorizontalAlign="Center" />
      <ItemStyle HorizontalAlign="Center" />
   </asp:TemplateField>
但是,即使在网格上显示的数据库中给定了值,该值也始终为null

页面加载时,将显示以下值:
但是,单击按钮时该值为null(clickedButton方法)。

一个非常快速而简单的解决方案是向GridView添加一个标签,并将其Visibility设置为false

<asp:TextBox ID="tbjan" runat="server" Text='<%# Eval("mJan") %>'></asp:TextBox>
<asp:Label ID="tbjanLabel" runat="server" Text='<%# Eval("mJan") %>' Visible="false"></asp:Label>

作为VDWWD响应的补充,请确保页面没有调用回发,也没有缺少来自gridview的引用。

TextBox value=((TextBox)(row.FindControl(“tbjan”)谢谢@vdwwd!但是,代码检索Bind中设置的值。我希望它能够恢复用户更改的内容。例如,单元格的原始值为10,用户在文本框中更改为11。当按下按钮时,我想要的是11,而不是10。这正是她所需要的,非常感谢你的帮助。回发发生得更早,清除了用户插入到网格中的内容。谢谢
protected void clickedButton(object sender, System.EventArgs e)
{
  foreach (GridViewRow row in grvMyTest.Rows) //Running all lines of grid
  {
      TextBox value = ((TextBox)(row.Cells[0].FindControl("mJan")));
   }
}
<asp:TextBox ID="tbjan" runat="server" Text='<%# Eval("mJan") %>'></asp:TextBox>
<asp:Label ID="tbjanLabel" runat="server" Text='<%# Eval("mJan") %>' Visible="false"></asp:Label>
 TextBox value = (TextBox)(row.FindControl("tbjan"));
 Label lbl = (Label)(row.FindControl("tbjanLabel"));

 if (lbl.Text == value.Text)
 {
     //no change
 }