views:

149

answers:

1

I have an ObjectDataSource (but perhaps this question is the same for all kinds of DataSources which support parameter collections):

<asp:ObjectDataSource ID="MyObjectDataSource" runat="server" 
    TypeName="MyData"
    OldValuesParameterFormatString="original_{0}" 
    SelectMethod="GetMyData" >
    <SelectParameters>
        <asp:ControlParameter ControlID="MyTextBox" Name="MyParameter" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

As you can see there is a ControlParameter bound to a TextBox on the aspx page. So the content of this TextBox is a parameter for my SelectMethod. But there is a special button on the page: When this button is clicked and a postback occurs I don't want that the DataSource extracts the content of the TextBox to control the selection, instead I want to set a specific hard value "x" as the selection parameter.

How can I do that? Can I "disable" in some way the ControlParameter when this specific button is clicked and set my special value instead? Or is there any other way?

Thank you for feedback in advance!

A: 

I've found this solution myself:

I've replaced the asp:ControlParameter by a "generic" parameter:

<SelectParameters>
    <asp:Parameter Name="MyParameter" Type="String" />
</SelectParameters>

...and then in the event handler for the special button:

MyObjectDataSource.SelectParameters["MyParameter"].DefaultValue = "x";

In the event handler of the button which shall run the selection by the TextBox content:

MyObjectDataSource.SelectParameters["MyParameter"].DefaultValue = MyTextBox.Text;

I don't know if this is a good solution or if it can have unwished side effects. But at the moment it works. (I was wondering anyway what's the purpose of "generic" parameters. Perhaps exactly this: "Unbound" parameters to be set only by code-behind (aside from being the base class of customized parameter classes)).

Slauma