Saturday, February 19, 2011

Dynamically built SelectCommand for GridView SqlDataSource in asp.net

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?

From stackoverflow

0 comments:

Post a Comment