Home » c# » c# – asp.net can't find property specified by DataObjectTypeName in ObjectDataSource-Exceptionshub

c# – asp.net can't find property specified by DataObjectTypeName in ObjectDataSource-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I have a Gridview that has it’s DataSource as an ObjectDataSource, with no templates on the .aspx page. This is a legacy application that I have inherited.

When attempting to Edit and Update a row’s content in the Gridview I get an error:

Sys.WebForms.PageRequestManagerServerErrorException: Could not find a
property named ‘rsvpCountry’ on the type specified by the
DataObjectTypeName property in ObjectDataSource ‘ObjectDataSource1’.

I’m not sure what is causing the problem. I’ve tried to narrow down the issue regarding ‘rsvpCountry’ but I’m not seeing where the problem is. Any help trying to figure out how to resolve this error would be greatly appreciated, as I need the Update for row content to work.

<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" OnRowDataBound="GridView1_RowDataBound"
    AutoGenerateEditButton="True" AutoGenerateDeleteButton="True" OnDataBound="GridView1_DataBound" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"></asp:ObjectDataSource>

and the code behind page (.cs) assigns content to the ObjectDataSource.

protected _MyENT obj = new _MyENT();
protected _MyBLL bll = new _MyBLL();

protected void Page_Load(object sender, EventArgs e)
{
    //lblTitle.Text = obj.GetType().ToString();
    ObjectDataSource1.DataObjectTypeName = obj.GetType().ToString();
    ObjectDataSource1.TypeName = bll.GetType().ToString();
    ObjectDataSource1.SelectMethod = "GetData";
    ObjectDataSource1.InsertMethod = "Insert";
    ObjectDataSource1.UpdateMethod = "Update";
    ObjectDataSource1.DeleteMethod = "Delete";
}

Here is the BLL file’s code regarding the ‘Update’ method:

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
public bool Update(_MyENT ent)
{
    MyXSD.MyDataTable table = Adapter.GetData();
    foreach (Rsvp.MyRow row in table.Rows)
    {
        if (row.id == ent.id)
        {
            try
            {
                row.InviteeID = ent.InviteeID;
                row.rsvpFirstName = ent.rsvpFirstName;
                row.rsvpLastName = ent.rsvpLastName;
                row.rsvpTitle = ent.rsvpTitle;
                row.rsvpAddress1 = ent.rsvpAddress1;
                row.rsvpAddress2 = ent.rsvpAddress2;
                row.rsvpAddress3 = ent.rsvpAddress3;
                row.rsvpAddress4 = ent.rsvpAddress4;
                row.rsvpCity = ent.rsvpCity;
                row.rsvpState = ent.rsvpState;
                row.rsvpZip = ent.rsvpZip;
                row.rsvpCountry = ent.rsvpCountry;
                row.rsvpTel = ent.rsvpTel;
                row.rsvpEmail = ent.rsvpEmail;
                row.rsvpType = ent.rsvpType;
                row.rsvpConfirmationSent = ent.rsvpConfirmationSent;
                row.rsvpYes = ent.rsvpYes;
                row.dinnerYes = ent.dinnerYes;
                row.lectureYes = ent.lectureYes;
                row.receptionYes = ent.receptionYes;
                row.guestOfID = ent.guestOfID;
                row.mealPreference = ent.mealPreference;
            }
            catch (Exception x)
            {
                return false;
            }
            row.updated = DateTime.Now;
        }
    }
    int rowsAffected = Adapter.Update(table);
    return rowsAffected == 1;
}

and here’s the ENT file:

public class _MyENT
{
    public _MyENT()
    {    
        //
        // TODO: Add constructor logic here
        //
    }
    private int _id;
    private int _InviteeID;
    private string _rsvpFirstName;
    private string _rsvpLastName;
    private string _rsvpTitle;
    private string _rsvpAddress1;
    private string _rsvpAddress2;
    private string _rsvpAddress3;
    private string _rsvpAddress4;
    private string _rsvpCity;
    private string _rsvpState;
    private string _rsvpZip;
    private string _rsvpCountryCode;
    private string _rsvpTel;
    private string _rsvpEmail;
    private byte _rsvpType;
    private bool _rsvpConfirmationSent;
    private bool _rsvpYes;
    private bool _lectureYes;
    private bool _dinnerYes;
    private string _mealPreference;
    private bool _receptionYes;
    private int _guestOfID;
    private string _guestOfName;
    private DateTime _updated;

    public int id { get { return _id; } set { _id = value; } }
    public int InviteeID { get { return _InviteeID; } set { _InviteeID = value; } }
    public string rsvpFirstName { get { return _rsvpFirstName; } set { _rsvpFirstName = value; } }
    public string rsvpLastName { get { return _rsvpLastName; } set { _rsvpLastName = value; } }
    public string rsvpTitle { get { return _rsvpTitle; } set { _rsvpTitle = value; } }
    public string rsvpAddress1 { get { return _rsvpAddress1; } set { _rsvpAddress1 = value; } }
    public string rsvpAddress2 { get { return _rsvpAddress2; } set { _rsvpAddress2 = value; } }
    public string rsvpAddress3 { get { return _rsvpAddress3; } set { _rsvpAddress3 = value; } }
    public string rsvpAddress4 { get { return _rsvpAddress4; } set { _rsvpAddress4 = value; } }
    public string rsvpCity { get { return _rsvpCity; } set { _rsvpCity = value; } }
    public string rsvpState { get { return _rsvpState; } set { _rsvpState = value; } }
    public string rsvpZip { get { return _rsvpZip; } set { _rsvpZip = value; } }
    public string rsvpCountry { get { return _rsvpCountryCode; } set { _rsvpCountryCode = value; } }
    public string rsvpTel { get { return _rsvpTel; } set { _rsvpTel = value; } }
    public string rsvpEmail { get { return _rsvpEmail; } set { _rsvpEmail = value; } }
    public byte rsvpType { get { return _rsvpType; } set { _rsvpType = value; } }
    public bool rsvpConfirmationSent { get { return _rsvpConfirmationSent; } set {    _rsvpConfirmationSent = value; } }
    public bool rsvpYes { get { return _rsvpYes; } set { _rsvpYes = value; } }
    public bool lectureYes { get { return _lectureYes; } set { _lectureYes = value; } }
    public bool dinnerYes { get { return _dinnerYes; } set { _dinnerYes = value; } }
    public string mealPreference { get { return _mealPreference; } set { _mealPreference = value; } }
    public bool receptionYes { get { return _receptionYes; } set { _receptionYes = value; } }
    public int guestOfID { get { return _guestOfID; } set { _guestOfID = value; } }
    public string guestOfName { get { return _guestOfName; } set { _guestOfName = value; } }
    public DateTime updated { get { return _updated; } set { _updated = value; } }
}
How to&Answers: