本文介绍了将列绑定到与gridview不同的实体源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个gridview绑定到一个Entity DataSource(权限)。其中一列列出了UserId,它是另一个表中的主键。如何用User Entity DataSource将相应的Name替换为UserId?解决方案
将其排序..
< asp:TemplateField HeaderText =ApprovedBySortExpression =ApprovedBy>
< ItemTemplate>
< asp:Label ID =lblUserrunat =serverText ='<%#GetApprover(Eval(ApprovedBy)ToString())%>'/>
< / ItemTemplate>
< / asp:TemplateField>
和代码:
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;
}
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?
解决方案
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;
}
这篇关于将列绑定到与gridview不同的实体源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!