C# 获取当前登录用户以在ASP.NET C的gridview中显示其记录#

C# 获取当前登录用户以在ASP.NET C的gridview中显示其记录#,c#,asp.net,C#,Asp.net,我试图在gridview中显示当前登录的用户及其记录。如果用户登录,则可以查看与其关联的所有记录和表。这是我的一个简单代码 <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Account.aspx.cs" Inherits="LibrarySystem.Member.MyAccount" %> <asp:Content ID="C

我试图在gridview中显示当前登录的用户及其记录。如果用户登录,则可以查看与其关联的所有记录和表。这是我的一个简单代码

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Account.aspx.cs" Inherits="LibrarySystem.Member.MyAccount" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h3>
    My Account</h3>
<p>
    &nbsp;</p>
<p>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        CellPadding="4" DataKeyNames="lenid" DataSourceID="useraccountDataSource" 
        ForeColor="#333333" GridLines="None">
        <RowStyle BackColor="#EFF3FB" />
        <Columns>
            <asp:BoundField DataField="lenid" HeaderText="Lend ID" InsertVisible="False" 
                ReadOnly="True" SortExpression="lenid" />
            <asp:BoundField DataField="bookid" HeaderText="Book ID/ISBN" 
                SortExpression="bookid" />
            <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" 
                SortExpression="EmployeeID" />
            <asp:BoundField DataField="department" HeaderText="Department" 
                SortExpression="department" />
            <asp:BoundField DataField="dateborrowed" HeaderText="Date borrowed" 
                SortExpression="dateborrowed" />
            <asp:BoundField DataField="datereturned" HeaderText="Date returned" 
                SortExpression="datereturned" />
        </Columns>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <asp:SqlDataSource ID="useraccountDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>" 
        SelectCommand="SELECT [lenid], [bookid], [EmployeeID], [department], [dateborrowed], [datereturned] FROM [LendTable] WHERE ([EmployeeID] = @EmployeeID)">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridView1" Name="EmployeeID" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    </p>
<p>
    &nbsp;</p>
</asp:Content>

我的帐户

EmployeeID与用户名相同(我已将aspnet用户数据库指向我自己的数据库)。我想只向当前登录用户显示登录用户的记录

任何帮助都将不胜感激;)
提前感谢。

既然您在问题中说
员工ID是用户名
,您可以按如下方式访问登录的用户名:

HttpContext.Current.User.Identity.Name

经过一天的修补和编程,我终于得到了它:D