문제

I have my ObjectDataSource enstantiated like so:

<asp:ObjectDataSource ID="x" runat="server" InsertMethod="xx"
    SelectMethod="xxx" TypeName="xxxx"
    UpdateMethod="xxxxx">

Select, insert, update methods do as you would expect; Select all data, insert data and update data. My question is, is there a way I can assign another method e.g. a second select which selects different data or maybe a deleteMethod?

도움이 되었습니까?

해결책

YES, you can. For any operation there is always an event raised before the operation is actually performed and one event after performing the operation.

So, in your case, it is select operation. the event raised just before this operation will be x.Selecting.

Set this event handler in .aspx as

<asp:ObjectDataSource ID="x" runat="server" InsertMethod="xx"
SelectMethod="xxx" TypeName="xxxx"
UpdateMethod="xxxxx" OnSelecting="x_Selecting">

Now, in this Selecting Event Handler change the select method dynamically, where 'x' is the ID of your object DataSource.

protected void x_Selecting()
{ x.SelectMethod="My_new_SelectMethod";
}

When select operation is performed, this new method will be used and then x.Selected event will get raised.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top