2

I have a gridview in a page and it have a template field:

        <asp:TemplateField>
            <ItemTemplate>
                <asp:TextBox ID="txtReturn" runat="server" Text="0"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>

And I wrote some code in a command button Click Event to read TextValue of this text box :

int i = 0;
        foreach (GridViewRow row in grdFactor.Rows)
        {
            TextBox txt = (TextBox)(row.FindControl("txtReturn"));
            int ret = 0;
            try
            {
                ret = Int32.Parse(txt.Text);
                if (ret > 0 && ret < factor.Orders[i].Entity)
                {
                    factor.Orders[i].updateReturn(ret);
                }
            }
            catch (Exception ex) { }

            i++;
        }

But the value of txt.Text is always Zero. Could you help me please? Thanks.

1 Answer 1

1

When are you calling DataBind() on the Grid or Page? Often times developers will Bind the data twice and override the data recieved from Request.Form.

Be sure to check the Page.IsPostBack boolean.

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        this.myGrid.DataSource = list;
        this.myGrid.DataBind();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.