ASP.NET 对象数据源问题
这是我所有类的共同结构:
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() { }
}
我通过 winform 顺利地使用这些类。
但是,在使用 ASP.NET 时,当我尝试为 GridView 配置对象数据源时,我在数据源配置向导
中找不到方法名称。即他们没有出现。于是我的方法就变得毫无用处了。
我无法改变我所有课程的总体结构。我还有一个为他们编写的代码生成器。我必须使用ObjectDataSources
。
我的第一个问题是,他们为什么不出现?
而且,我该怎么做才能让他们出现?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ObjectDataSource 在指定类型中查找与更新/插入方法名称和提供的更新/插入参数的签名相匹配的方法。
您的 SaveOrUpdate 方法位于实例化类上,并且 ObjectDataSource 将找不到匹配的方法签名。
根据您所拥有的信息,如果您必须使用 ObjectDataSources,您可能需要考虑使用包装器方法。 示例。
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.
我不太确定,但您可以尝试用 DataObjectAttribute 和带有 DataObjectMethodAttribute。我已经很久没有使用
ObjectDataSource
了,所以可能会忘记一些东西。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.