Search code examples
c#asp.nettrimformview

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


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 ?


Solution

  • formView.Controls
        .OfType<System.Web.UI.WebControls.TextBox>()
        .ToList()
        .ForEach(t => t.Text = t.Text.Trim());