DataSource Parameter with dynamic value

  • Thread starter Erik Funkenbusch
  • Start date
E

Erik Funkenbusch

ASP.NET 2.0

I have a SqlDataSource that i'd like to pass the UserID of the user defined
by the Membership provider.

So, I thought I'd do something like this:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:acpConnectionString %>"
SelectCommand="SELECT [balance] FROM [accounts] WHERE ([UserID] = @UserID)" EnableViewState="False">
<SelectParameters>
<asp:parameter Name="UserID" Type="Object" DefaultValue="<%= Membership.GetUser(false).ProviderUserKey %>"/>
</SelectParameters>
</asp:SqlDataSource>

ProviderUserKey is a GUID, and my SQL Data type is a uniqueidentifer. This
doesn't generate any kind of exception, but it just returns no data.

If, however, I use a SessionParameter, and copy the ProviderUserKey into a
Session variable, it works and returns the record as expected.

It seems like the ASP code in the Parameter tag isn't executing, any ideas
how to fix this? I'd rather not use the session variable if I don't have
to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top