[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

<asp:LoginName> tag value, used as parameter in SqlDataSource ???

Posted on 2009-02-20
3
Medium Priority
?
892 Views
Last Modified: 2012-05-06
Hi,

Wondering, is there a way I can ...
Use the UserName value that is returned from Code Snippet One (the asp:LoginName tag)

and use it as a parameter in my SqlDataSource later on the page ...
I basically need the userName obtained from the LoginName tag placed in code Snippet 2 at the marker _Parameter, but have been unable to achieve this so far, I've tried it a couple of ways ... like this ... and also in the code, but have encounted no success.

any Ideas?
Code Snippet One:
    <asp:LoginView ID="LoginView1" runat="server">
        <LoggedInTemplate>
            UserName&nbsp;&nbsp;<asp:LoginName ID="LoginName1" runat="server" />
        </LoggedInTemplate>
    </asp:LoginView>
    <p>Please select a folder to upload your file to.  <b>If no folder is selected file will be placed in the default folder.</b></p>
    <asp:GridView ID="GridView_FolderName_Selector" runat="server" AutoGenerateColumns="False" AllowPaging="False" 
    DataSourceID="SqlDataSource1">
        <Columns>
            <asp:TemplateField HeaderText="Selection">
                <ItemTemplate>
                    <asp:CheckBox ID="FolderNameSelector" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="FolderName" HeaderText="FolderName" 
            SortExpression="FolderName" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ConnectionStrings:LocalSqlServer%>" 
    SelectCommand="SELECT [FolderName] FROM [FolderPermissions] WHERE UserName = _Parameter"></asp:SqlDataSource>

Open in new window

0
Comment
Question by:BrianNDN
  • 2
3 Comments
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23697835
Sure, just use the authenticated user name.

User.Identity.Name
0
 

Author Comment

by:BrianNDN
ID: 23697841
I've done that in the cs file and played with it, but wasn't seeming to get it to work.
Can that be inserted like:
SelectCommand="SELECT [FolderName] FROM [FolderPermissions] WHERE UserName = User.Identity.Name"></asp:SqlDataSource>

??? if so, Do I need to put it as:  @User.Identity.Name
?

Thanks
0
 
LVL 15

Accepted Solution

by:
aibusinesssolutions earned 2000 total points
ID: 23697852
No, you'll want to add a parameter

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
        SelectCommand="SELECT [FolderName] FROM [FolderPermissions] WHERE ([UserName] = @UserName)"
        ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>">
        <SelectParameters>
            <asp:Parameter DefaultValue="@UserName" Name="UserName" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

And then in the form load, put this.
SqlDataSource1.SelectParameters("UserName").DefaultValue = User.Identity.Name

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

829 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