2011-04-30 219 views
0

我试图显示当前登录的用户及其在gridview中的记录。如果用户登录,他可以查看与他相关的所有记录和表格。这是我的一个简单的代码。获取当前登录的用户在ASP.NET的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用户数据库指向我自己的数据库)。我想仅将登录用户的记录显示给当前登录的用户。

任何帮助将不胜感激;) 在此先感谢。

回答

1

既然你的疑问,employeeId is the Username,你可以访问登录的用户名如下表示:

HttpContext.Current.User.Identity.Name 
+0

嗯,我想我之前已经试过这一点。让我再试一次... – Loupi 2011-04-30 05:01:59

+0

经过一整天的修补和编程,我终于明白了:D – Loupi 2011-05-03 04:24:48

相关问题