问题:我在 .aspx 文件中声明了 2 个数据源,如下所示:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="UsuarioDelete" SelectMethod="SelectMyAllNotME_Data" TypeName="BLLayer.Usuarios" OnInserted="ObjectDataSource_Inserted">
<DeleteParameters>
<asp:ControlParameter ControlID="ConfirmDialogBox1" Name="id_usuario" PropertyName="Aceptar_CommandName" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:SessionParameter DefaultValue="1" Name="id_usuario" SessionField="id_usuario" Type="Int32" />
<asp:SessionParameter DefaultValue="1" Name="id_pais" SessionField="id_pais" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" DeleteMethod="UsuarioDelete" SelectMethod="SelectMyAllNotME_Data" TypeName="BLLayer.Usuarios" OnInserted="ObjectDataSource_Inserted">
<DeleteParameters>
<asp:ControlParameter ControlID="ConfirmDialogBox1" Name="id_usuario" PropertyName="Aceptar_CommandName" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="id_emp" QueryStringField="id_emp" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
方法“SelectMyAllNotME_Data”是一种重载方法,在一个他接收 2 个值而在另一个只接收一个值时,它用于过滤信息。我想做的是在我的 onLoadPage 方法中是这样的:
if (Request.QueryString["id_emp"] != null)
{
GridViewUsers.DataSource = ObjectDataSource2.SelectMethod;
GridViewUsers.DataMember = ObjectDataSource2.SelectMethod;
}
else
{
GridViewUsers.DataSource = ObjectDataSource1.SelectMethod;
GridViewUsers.DataMember = ObjectDataSource1.SelectMethod;
}
}
我已经尝试过了,但它不起作用,有人可以帮助我吗?