使用实体框架检索cookie信息以绑定数据网格中的数据

时间:2011-05-17 23:33:30

标签: asp.net entity-framework-4

我正在尝试检索登录系统的人的用户名并使用数据网格(使用实体框架)将其映射,以便我只能提取与他相关的记录

我能够从身份验证cookie中提取用户名,但是如果我只使用与该特定用户相关的信息来填充数据网格,我将无法使用该数据

IPrincipal p = HttpContext.Current.User;
        // p.Identity.Name : this is what we will use to call the stored procedure to get the data and populate it
        string userid = p.Identity.Name;

这是我用来获取用户名的代码,然后针对存储过程执行该代码以检查数据库中是否存在用户名

然而我的困惑是,现在我有了用户名,我如何使用它来绑定数据库中的数据

实体框架的代码如下所示

<asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="name=LicensingEntities1" 
        DefaultContainerName="LicensingEntities1" EnableFlattening="False" 
        EntitySetName="commissions" EntityTypeFilter="commission">
    </asp:EntityDataSource>
    <br />

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" 
        DataKeyNames="School_Name,LoginName" DataSourceID="EntityDataSource1">
        <Columns>
            <asp:BoundField DataField="School_Name" HeaderText="School_Name" 
                ReadOnly="True" SortExpression="School_Name" />
            <asp:BoundField DataField="School_City" HeaderText="School_City" 
                SortExpression="School_City" />
            <asp:BoundField DataField="School_State" HeaderText="School_State" 
                SortExpression="School_State" />
            <asp:BoundField DataField="LoginName" HeaderText="LoginName" ReadOnly="True" 
                SortExpression="LoginName" />
            <asp:BoundField DataField="Current_Sales" HeaderText="Current_Sales" 
                SortExpression="Current_Sales" />
            <asp:BoundField DataField="Commission1" HeaderText="Commission1" 
                SortExpression="Commission1" />
            <asp:BoundField DataField="Pay_Period_start_date" 
                HeaderText="Pay_Period_start_date" 
                SortExpression="Pay_Period_start_date" />
            <asp:BoundField DataField="Pay_Period_End_date" 
                HeaderText="Pay_Period_End_date" SortExpression="Pay_Period_End_date" />
        </Columns>
    </asp:GridView>

谢谢

0 个答案:

没有答案