• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

Set parameters for gridview select statement

I have set up a grid view and I want to use a stored procedure to populate the grid. This works if I hard code a value, but I want to use value of HttpContext.Current.User.Identity.Name.

For example
SelectCommand="sp_SelectStatement 'mysearchitem' works but
SelectCommand="sp_SelectStatement '<%=HttpContext.Current.User.Identity.Name %>'
I've also tried using <%#eval(HttpContext.Current.User.Identity.Name)%> and this doesn't work either.

1 Solution
Dustin HopkinsSenior Web DeveloperCommented:
you should use a parameterised query. then just set the username to a session variable in the pageload. and set a sessionparameter in the markup.
 Sub page_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("username") = HttpContext.Current.User.Identity.Name
    End Sub
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:urodataConnectionString %>"
            SelectCommand="Testselectuser" SelectCommandType="StoredProcedure">
                <asp:SessionParameter Name="name" SessionField="username" />

Open in new window

kirkheaton25Author Commented:
That was perfect, thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now