Best way to trim value in textbox before save/insert using formview into datasource

Sarawut Positwinyu picture Sarawut Positwinyu · May 17, 2012 · Viewed 26.7k times · Source

By triming i mean something like.

First name "John " -> trim to "John"

Last name "Lennon " -> trim to "Lennon"

I have those Textbox in FormView, binding with property using Bind("FirstName").

The FormView bind with Entity Datasource.

I want those value to be trim before saving, what is the best way to do this ?

Answer

L.B picture L.B · May 17, 2012
formView.Controls
    .OfType<System.Web.UI.WebControls.TextBox>()
    .ToList()
    .ForEach(t => t.Text = t.Text.Trim());