?
Solved

Set parameters for gridview select statement

Posted on 2008-06-24
2
Medium Priority
?
775 Views
Last Modified: 2012-02-02
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 %>'
doesn't.
I've also tried using <%#eval(HttpContext.Current.User.Identity.Name)%> and this doesn't work either.

Thanks.
0
Comment
Question by:kirkheaton25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 2000 total points
ID: 21857716
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.
'PageLoad
 Sub page_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("username") = HttpContext.Current.User.Identity.Name
    End Sub
 
'FrontEnd
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:urodataConnectionString %>"
            SelectCommand="Testselectuser" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:SessionParameter Name="name" SessionField="username" />
            </SelectParameters>
        </asp:SqlDataSource>

Open in new window

0
 
LVL 1

Author Closing Comment

by:kirkheaton25
ID: 31470134
That was perfect, thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question