views:

91

answers:

1

I have a formview that I select data based on values I get from referencing a master page. I want to set my parameters to some value behind code instead of storing those values in a hidden field and setting my parameter source to a control(hidden field control)

IS THIS POSSIBLE? If so - How?

I'm using an SQL datasource

+1  A: 

Handle the OnSelecting event for your datasource. From there you can get a reference to the command object used for the query and modify it's parameters collection.

You didn't share exactly what kind of datasource you're using, but here's an example with an SqlDataSource:

Markup:

<asp:SqlDataSource runat="server" ID="MyDataSource" OnSelecting="OnMyDataSourceSelecting" ...>
    <SelectParameters>
        <asp:Parameter Type="..." Name="SomeParameter" />
    </SelectParameters>
</asp:SqlDataSource>

Note that it's just a plain asp:Parameter. Not a Session parameter. Not a Control parameter. Not a QueryString parameter. None of that. Just a plain generic parameter. It sounds like you're using a wizard to set these up, and as I rarely use the wizard I'm not sure how you tell it to use the generic parameter. But you can just pick one and then go back and fix the markup when the wizard is done.

Code-behind:

void OnMyDataSourceSelecting(object sender, SqlDataSourceSelectingEventArgs e)
{
     e.Command.Parameters["@SomeParamter"].Value = "somevalue";
}
Joel Coehoorn
ok but when I'm prompted to define parameters what parameter source would I select - Session,cookie,control,form,profile,querystring. I'm not sure I follow.
Eric