I created a gridview containing textbox that are populated in the backend:
<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>
In the backend I would like that when the user clicks the button I would like to retrieve the value of the TextBox to update in the database:
<asp:Button runat="server" Text="Alter values" id="testButton" OnClick="clickedButton" />
Back-end code:
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")));
}
}
But the value is always null even having given in the database that appear on the grid.
When the page loads the values appear: Grid But, the value is null when the button as clicked (clickedButton method).
TextBox value = ((TextBox)(row.FindControl("tbjan")));