Edit record is not working.

Jan 12, 2014 at 6:18 PM
Hi Binod, great work, love the framework.

For edit record -> Save, Page.IsValid property is false always.

I did some fix, hope will be helpful.

For Edit record issue on all events 'Edit', 'Save', 'Cancel' in ScrudEvents.cs.
I commented the container clear and form load logic and call new method to just fill the values to form controls without clear container.

//Clear the form container.
//formContainer.Controls.Clear(); --commented

using (System.Data.DataTable table = new System.Data.DataTable())
//Load the form again.
//this.LoadForm(this.formContainer, table); --commented
this.FillFormValues(this.formContainer, table); --added new method

Added below new method in FormFactory.cs file.

/// <summary>
    /// To fill values in case of Edit record
    /// </summary>
    /// <param name="container"></param>
    /// <param name="values"></param>
    private void FillFormValues(Panel container, System.Data.DataTable values)
        using (System.Data.DataTable table = MixERP.Net.WebControls.ScrudFactory.Data.TableHelper.GetTable(this.TableSchema, this.Table, this.Exclude))
            if(table.Rows.Count > 0)
                foreach(System.Data.DataRow row in table.Rows)
                    string columnName = MixERP.Net.Common.Conversion.TryCastString(row["column_name"]);
                    string defaultValue = MixERP.Net.Common.Conversion.TryCastString(row["column_default"]);
                    bool isSerial = defaultValue.StartsWith("nextval", StringComparison.OrdinalIgnoreCase);
                    string parentTableColumn = MixERP.Net.Common.Conversion.TryCastString(row["references_field"]);
                    string dataType = MixERP.Net.Common.Conversion.TryCastString(row["data_type"]);

                            case "national character varying":
                            case "character varying":
                            case "national character":
                            case "character":
                            case "char":
                            case "varchar":
                            case "nvarchar":
                            case "text":                                
                            case "smallint":
                            case "integer":
                            case "bigint":
                            case "numeric":
                            case "money":
                            case "double":
                            case "double precision":
                            case "float":
                            case "real":
                            case "currency":
                                TextBox t = (TextBox)formContainer.FindControl(columnName + "_textbox");
                                if(t != null)
                                    if (values.Rows.Count <= 0)
                                        t.Text = string.Empty;
                                        t.Text = MixERP.Net.Common.Conversion.TryCastString(values.Rows[0][columnName]); 
                            case "date":
                                Common.DateTextBox dt = (Common.DateTextBox)formContainer.FindControl("plch_" + columnName + "_textbox").Controls[0];
                                if(dt != null)
                                    if (values.Rows.Count <= 0)
                                        dt.Text = string.Empty;
                                        dt.Text = MixERP.Net.Common.Conversion.TryCastString(values.Rows[0][columnName]);
                            case "boolean":
                                RadioButtonList r = (RadioButtonList)formContainer.FindControl(columnName + "_radiobuttonlist");
                                list.Add(new KeyValuePair<string, string>(columnName, r.Text));
                            case "bytea":
                                FileUpload f = (FileUpload)formContainer.FindControl(columnName + "_fileupload");
                                string file = MixERP.Net.WebControls.ScrudFactory.Controls.ScrudFileUpload.UploadFile(f);
                                list.Add(new KeyValuePair<string, string>(columnName, file));
                                imageColumn = columnName;

                        DropDownList d = (DropDownList)formContainer.FindControl(columnName + "_dropdownlist");                            
                        if (values.Rows.Count <= 0)
                            d.SelectedIndex = -1;
                            string ddlText = MixERP.Net.Common.Conversion.TryCastString(values.Rows[0][columnName]);
                            if (d.Items.Count > 0 && d.Items.FindByValue(ddlText) != null)
                                d.SelectedIndex = d.Items.IndexOf(d.Items.FindByValue(ddlText));
                        //list.Add(new KeyValuePair<string, string>(columnName, d.Text));
Jan 12, 2014 at 7:46 PM
Wow, long thread. Been busy with my new song, I have been a little carried away. :)

I will have a look on this carefully and let you know. Meanwhile, I would suggest you to create an acoount in the forum and paste this issue there. It would be helpful for putting all discussions in one place.


Jan 14, 2014 at 5:06 PM
Sunview, thank you for your input and suggestion.

I could not reproduce the problem you stated and it seems to me that the Page.IsValid() is working properly on Save event for Edit. Could you please revert to the latest commit and confirm?

Thank you.