开发者

Retrieving cookie information to bind data in a datagrid using the entity framework

I am trying to retrieve the username of the person logged into the system and map it with a datagrid (using the entity framework ) so that I can only pull in the records which are relevant to him

I was able to pull in the user name from the authentication cookie but I am at a loss with regards to how I can use that data in populating the datagrid with just information pertaining to that particular user

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;

This is the code I use to get user name which is then executed against a stored procedure to check if the user name exists in the database

However my confusion is that now that I have the username,how do I use it to bind data from the database

The code for the entity framework is given below

<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>

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜