0

This is the common structure of all of my classes:

public class User
{
    public int ID { get;set; }
    public string User_name { get; set; }
    public string Pass_word { get; set; }
    public string UserTypeCode { get; set; }

    public int SaveOrUpdate()
    {
        int id = -1;

        if (this._ID <=0)
        {
            id = this.Save();
        }
        else
        {
            bool success = this.Update();

            if(success)
            {
                id = this._ID;
            }
            else
            {
                throw new Exception("Update failed!");
            }
        }

        return id;
    }

    private int Save() { }
    private bool Update() { }
    public static User Get(int id) { }
    public static List<User> Get() { }
    public bool Delete() { }
}

I was using these classes smoothly with winforms.

But while working with ASP.NET, when I try to configure the object data source for a GridView, I don't find the method-names in the Data Source Configuration Wizard. I.e. they are not showing up. So my methods became useless.

I can't change this general structure of all of my classes. I have also a code generator written for them. And I must use ObjectDataSources.

My first question is, why don't they show up?

And, what should I do to make them show up?

2
  • Could you post the code from the aspx page and/or code-behind? That might be more helpful in spotting errors. Commented Nov 17, 2009 at 18:19
  • Oh nevermind, I guess your saying you can't even get the tags configured. Commented Nov 17, 2009 at 18:30

2 Answers 2

3

ObjectDataSources look for methods within the type specified that match the signature of the update/insert method name and the update/insert parameters provided.

Your SaveOrUpdate method is on an instantiated class, and the ObjectDataSource will not find a matching method signature.

From what you have, if you must use ObjectDataSources, you may want to consider using a wrapper method. Example.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 from me. Signature is important. So my answer is not correct.
1

I am not quite sure, but you can try to mark this class with DataObjectAttribute and CRUD methods with DataObjectMethodAttribute. I did not use ObjectDataSource for ages, so can forget something.

1 Comment

I know, you need special signature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.