Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems updating a date column in using GridView
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01236618
Message ID:
01237422
Vues:
17
Hi Kevin,

Thank you for your reply. My question was actually more about why I was getting an error trying to update a date column to null when editing in a datagrid. I wasn't able to do it using the documented method of saving an updatable datagrid (see DataGrid In-place Editing Walkthrough, MM.net Developer Guide). So I tried a few different things and ended up creating a local bizobj and setting its properties explicitly from the grid and calling o.SaveEntity().
    protected void grdSurveys_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        try
        {
            string dateStr = (string)e.NewValues["survey_date"];

            // validate the date
            if (!Validatesurvey_date(dateStr))
            {
                lblMessage.Text = "Survey date is not in the correct format. Example: 4/13/2001";
                lblMessage.Visible = true;
            }
            else
            {
                Survey lSurvey = new Survey();
                this.grdSurveys.EditIndex = e.RowIndex;
                mmGridView gv = (mmGridView)sender;
                object rowPrimaryKey = gv.DataKeys[e.RowIndex].Value;
                lSurvey.LoadRow(rowPrimaryKey);

                // assign all the values to the appropriate DataTable Row
                DataRow editDataRow = lSurvey.DataRow;

                editDataRow["job_id"] = e.NewValues["job_id"];
                
                if (dateStr != null)
                {
                    if (dateStr.Trim() != String.Empty)
                        editDataRow["survey_date"] = DateTime.Parse(dateStr);
                    else
                        editDataRow["survey_date"] = DBNull.Value;
                }
                else
                    editDataRow["survey_date"] = DBNull.Value;

                editDataRow["lot_id"] = e.NewValues["lot_id"];
                editDataRow["address_line1"] = e.NewValues["address_line1"];
                editDataRow["address_line2"] = e.NewValues["address_line2"];
                editDataRow["city"] = e.NewValues["city"];
                editDataRow["state"] = e.NewValues["state"];
                editDataRow["zip"] = e.NewValues["zip"];

                // attempt to save the dataset
                mmSaveDataResult result = lSurvey.SaveEntity();

                // if there are errors display them above the datagrid
                if (result == mmSaveDataResult.RulesBroken)
                {
                    lblMessage.Text = lSurvey.Rules.GetAllBrokenRules();
                    lblMessage.Visible = true;
                }
                else
                {
                    lblMessage.Text = String.Empty;
                    lblMessage.Visible = false;
                }

            }
            this.grdSurveys.EditIndex = -1;
            e.Cancel = true;
        }
        catch (Exception ex)
        {
            e.Cancel = true;
            lblMessage.Text = ex.Message;
            lblMessage.Visible = true;
        }
    }
Govinda Berrio
GKG Inc.
Providence, RI
http://www.gkginc.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform