vote up 1 vote down
star

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?

flag
add comment

1 Answer:

vote up 0 vote down
check

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.

link|flag
add comment

Your Answer:

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.