Reputation: 4190
I have a gridview bound to an Entity DataSource (Permissions). One of the columns lists a UserId, which is the primary key in another table. How do I go about replacing that UserId with the corresponding Name form the Users Entity DataSource?
Upvotes: 0
Views: 2071
Reputation: 4190
Sorted it out..
<asp:TemplateField HeaderText="ApprovedBy" SortExpression="ApprovedBy" >
<ItemTemplate>
<asp:Label ID="lblUser" runat="server" Text='<%# GetApprover(Eval("ApprovedBy").ToString()) %>'/>
</ItemTemplate>
</asp:TemplateField>
and code behind:
protected string GetApprover(string ApproverId)
{
int approver = Convert.ToInt32(ApproverId);
var approversList = (from a in EntUsers.Users
where a.UserId == approver
select a.Name).FirstOrDefault();
return approversList;
}
Upvotes: 0
Reputation: 52241
You can try like...
<asp:TemplateField HeaderText="User Name" >
<ItemTemplate>
<asp:Label ID="lblUser" runat="server" Text='<%# Eval("ParentEntityName.Name")%>'
</ItemTemplate>
</asp:TemplateField>
Upvotes: 1
Reputation: 7539
You can do a lookup in your Users Entity Source the RowDataBound event of the Gridview.
Upvotes: 0