ObjectDataSource和select方法在同一类中
本文关键字:一类 select 方法 ObjectDataSource | 更新日期: 2023-09-27 18:00:00
是否可以在同一类中拥有对象数据源及其选择方法?
public class Class1(): System.Web.UI.Page
{
protected void Page_load(object sender,EventArgs e)
{
this.ObjectDataSource1.TypeName="Class1";
this.ObjectDataSource1.SelectMethod="GetData";
this.ObjectDataSource1.DataBind();
}
public Ilist<object> GetData()
{
//return list here
}
}
我收到错误"找不到TypeName属性中指定的类型"
不要手动键入,而是使用GetType方法:
this.ObjectDataSource1.TypeName = this.GetType().FullName;
这应该足够了。如果没有,您可以尝试AssemblyQualifiedName
而不是FullName
。