如果使用ObjectDataSource,则必须在一个类中编写更新和选择方法。也许您必须直接为该GridView编写一个类,以便将更新和选择方法委托给其他对象。
我认为这对你很有用:
[DataObject(true)]
public class SomeService
{
private Device d;
private YourUpdaterClass yuc;
public SomeService()
{
this.d = new Device();
this.yuc = new YourUpdaterClass();
}
[DataObjectMethod(DataObjectMethodType.Select, true)]
public List<YourType> Select()
{
return d.YourSelectMethod();
}
[DataObjectMethod(DataObjectMethodType.Update, true)]
public void Update(YourType yt)
{
yuc.YourUpdateMethod(yt);
}
}
以及ObjectDataSource:
<asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
SelectMethod="Select"
TypeName="SomeService"
DataObjectTypeName="YourType"
UpdateMethod="Update">
</asp:ObjectDataSource>