Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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