profile for Cullen Tsering at Stack Overflow, Q&A for professional and enthusiast programmers

Thursday, July 23, 2009

Populating controls in FormView Insert or Empty empty template with default values

FormView doesn't make it easy for a developer when he wants to populate the controls in a empty or insert template with default values.  After doing some search, I found out one way to accomplish this is to override ItemCreated event as follows:

        protected void fvMine_ItemCreated(object sender, EventArgs e)
        {
//if the current mode in insert mode
              if (fvMine.CurrentMode == FormViewMode.Insert)
              {
//get a reference to the control
                            txt = (TextBox) fvMine.Row.FindControl("txtCity");
                            if (txt != null)
                            {
// populate it with a default value
                                txt.Text = "New York";
                            }

0 comments:

Post a Comment

About Cullen

Cullen has been coding since 1991. He has been a Sr. Software Engineer/Architect for 11 years and counting. He enjoys coding for work as well as for fun. He loves learning from anyone and delights in sharing the little knowledge he possesses.

Followers