Search code examples
c#asp.netdata-bindingformview

RadioButtonList and TextBox not updating in FormView


I have an ASP.Net 4.0 FormView which is bound to a SQLDataSource, using SQL Server 2008. It opens in Edit Mode by default, and the binding and updating were working fine until today when I added one more RadioButtonList and TextBox to it. Now the new RadioButtonList and TextBox display data correctly, but when I update, their data doesn't get added to the database. Everything else still works as before. I'm sure I'm doing something dumb, but I'm under a time crunch and don't see it. I would love to post my HTML, but even in code blocks, every time I try to submit this question, I get an error message ("An error has occurred). So, here's what I can tell you: there is more than one RadioButtonList on the page, and more than one TextBox. The RadioButtonLists and TextBoxes that were on the page before today work fine. They display data from the database, and save data to the database. The new RadioButtonList is different in that it has an OnSelectedIndexChanged event, which causes the new TextBox value to change. The new TextBox uses formatting to display a date as MM/dd/yyyy, unlike the other TextBoxes which just display data straight from the database. Other than that, I can't see any differences.

Here's the code behind (rblComplete and tbDateCompleted are the new controls; fvEmpInfo is the FormView):

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;</code>

namespace EAS.telecom
{
    public partial class NewRolloutDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void UpdateFormView(object sender, FormViewUpdatedEventArgs e)
        {
            fvEmpInfo.DataBind();
            lbResult.Visible = true;
        }

        protected void setDateCompleted(object sender, EventArgs e)
        {
            foreach (Control control in fvEmpInfo.Controls)
            {
                RadioButtonList rblCompleted = (RadioButtonList)control.FindControl("rblComplete");
                TextBox tbDateCompleted = (TextBox)control.FindControl("tbDateCompleted");
                if (rblCompleted.SelectedValue == "True")
                    tbDateCompleted.Text = DateTime.Today.ToShortDateString();
                else
                    tbDateCompleted.Text = "";
            }
        }
    }
}

Solution

  • Man, is my face red. I knew it was something dumb. I hadn't added the two new fields to the SQLDataSource's UPDATE command. Please pay me no mind....