views:

3663

answers:

1

I'm working with a GridView that uses a SqlDataSource element that looks like this:

        <asp:SqlDataSource ID="InventoryDB" runat="server" ConnectionString="<%$ ConnectionStrings:InventoryConnectionString %>"
            SelectCommand="SELECT [Server], [Customer] FROM [Website] WHERE [Owner] = 'someOwner'">
        </asp:SqlDataSource>

I'd like to replace the 'someOwner' part of the where clause with something dynamic, like so:

SelectCommand="SELECT [Server], [Customer] FROM [Website] WHERE [Owner] = '<%# UserManager.getCurrentUser(Request) %>'"

But when I do this, it seems to use the literal text of the WHERE clause instead of evaluating my function call, which of course does not work. What is the right way to do this?

A: 

The proper way to handle that is to use parameters. The MSDN documentation on it is pretty thorough in showing how to use them.

User Parameters with Data Source Controls has some more detailed and accessible information on using parameters.

Jeromy Irvine