Solved

Set parameters for gridview select statement

Posted on 2008-06-24
2
763 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
2 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now