This is a migrated thread and some comments may be shown as answers.

[Solved] ObjectDataSource Parameter Problem

1 Answer 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Davis
Top achievements
Rank 2
John Davis asked on 28 Apr 2008, 01:28 AM

Suppose you want to bind a grid for asp.net in a user control to an ObjectDatasource. 
It is a problem if the subroutine for the SelectMethod of the ObjectDatasource has a parameter whose value depends on user context or on a value in another control on the user control.

You cannot get this parameter value in the code-behind of the user control.  For example, the subroutine for the SelectMethod could be in the code-behind of the user control.
BUT it will not work.  Because the ObjectDatasource activates this subroutine before there is any user context or any viewstate available in the user control.
So you cannot get the parameter value this way.

I solved the problem by:

1. Defining a label control (lblSCS_ID in this case ) in the user control that will be the source of the parameter value

      <asp:ObjectDataSource ID="ObjDataSourceGetPGC2forSCS_ID" runat="server" TypeName="BalancedFlow.Library.Manager.SCSManager"
       SelectMethod="GetPGC2forSCS" EnablePaging="false">
      
       <SelectParameters>
        <asp:ControlParameter Name="SCS_ID" ControlID="lblSCS_ID" PropertyName="Text" />
       </SelectParameters>

2. In the OnPreRender of the code-behind of the user control I set the value of the parameter.

 lblSCS_ID.Text = UserContext.Session.ScsId.Value.ToString();

Now when the ObjectDatasource activates the SelectMethod it will get the parameter value from lblSCS_ID.Text (The parametervalue will already be there).

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 01 May 2008, 11:49 AM
Hello John,

Thank you for sharing your solution with the community.
I am sure it will come in handy in some similar scenarios.
I have updated your Telerik points for your involvement.

Regards,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
John Davis
Top achievements
Rank 2
Answers by
Yavor
Telerik team
Share this question
or