Solved

Set parameters for gridview select statement

Posted on 2008-06-24
2
771 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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