I have a formview control, and on the ItemCreated
event, I am "priming" some of the fields with default values.
However, when I try to use the formview to insert, before the ItemInserting
event gets called, for some reason it calls ItemCreated
first. That results in the fields being over-written with the default values right before the insert happens.
How do I get it to not call the ItemCreated
event before the ItemInserting
event?
you need to use formview Databound event instead of formview ItemCreated event to set values, try like
protected void frm_DataBound(object sender, EventArgs e)
{
if (frm.CurrentMode == FormViewMode.Edit)//whatever your mode here is.
{
TextBox txtYourTextBox = (TextBox)frm.FindControl("txtYourTextBox");
txtYourTextBox.Text// you can set here your Default value
}
}
Also check this thread of similare issue FormView_Load being overwritten C# ASP.NET