我需要阻止来自auloading数据的objectdatasource并在后面的代码中管理它。 当我删除SelectMethod时,会出现以下问题
除非指定了SelectMethod,否则ObjectDataSource'DataSource'不支持Select操作。
这是我的objectDataSource
<asp:ObjectDataSource ID="DataSource" runat="server" TypeName="declaration_prod_liste"
EnablePaging="true" StartRowIndexParameterName="startrows"
MaximumRowsParameterName="pagesize"
SelectCountMethod="GetDataSourceCount">
</asp:ObjectDataSource>
答案 0 :(得分:1)
您可以在代码隐藏中的适当事件中设置/更改objectdatasource的SelectMethod
。例如,在下面的代码中,这是在Page_Load事件中完成的。
但是,您需要在html代码中指定其SelectMethod,然后在Selecting event
中取消它,如第二个代码段所示。
我假设您的objectdata源ID为DataSource1
。
另外,请确保在hmtl for objectdatasource中指定SelectMethod。
protected void Page_Load(object sender, EventArgs e)
{
DataSource1.SelectMethod = "SelectMethod";
GridView1.DataSourceID = DataSource1.ID ;
GridView1.DataBind();
}
您可以通过取消Selecting event
取消objectdatasource autopouplating,如下面的代码段所示。确保在objectdatasource html中订阅此事件。
protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
//puty your logic when to cancel and when not to cancel
e.Cancel = true;
}
Html应如下所示。
<asp:ObjectDataSource ID="DataSource1" runat="server" TypeName="declaration_prod_liste"
EnablePaging="true" StartRowIndexParameterName="startrows"
MaximumRowsParameterName="pagesize"
SelectCountMethod="GetDataSourceCount"
SelectMethod="SomeMethod"
OnSelecting ="ObjectDataSource1_Selecting" >
</asp:ObjectDataSource>