将 Repeater 与 Dictionary 绑定
我是 .NET 的新手,所以我正在为此苦苦挣扎。我有一个内容页面,带有转发器控件。我有一个字典,它是一个 Dictionary
。我希望转发器控件内的控件值从对象属性中获取 - 候选名称为 object.CandName
,候选电话为 object.Phone
等 。
我不知道如何使用 Eval
这种类型的字典 大多数示例都指向 Eval("Value")
,但它没有为我提供正确的值。请帮忙!
<asp:Content ID="Content2" ContentPlaceHolderID="content" Runat="Server">
<div id="rcontent">
<table>
<tr>
<td>
<asp:Label ID="lblerror" runat="server" Text="" Visible="true" CssClass="alert"></asp:Label>
</td>
</tr>
</table>
<div id ="rptdiv">
<asp:Repeater ID="Repeater1" runat="server" EnableViewState="false">
<ItemTemplate>
<div id="Div3">
<table class="GridViewStyleNoBorder" width=750px cellspacing="0" border="0" >
<tr>
<td class="PagerStyle" colspan="4">
<asp:Label ID="lblName" Runat="server"
Text='<%= Need the value of the [object].objectproperty from dictionary here %>' />
</td>
</tr>
</table>
</div>
这是我的 Page_Load
代码 - BLDecision
是我的业务层代码,它返回字典并且字典值是正确的。我在调试模式下检查了它们。
代码隐藏:
Dictionary(int, Dictionary(int, InterviewFeedback)) ;
CandIntDetails = new Dictionary(int, Dictionary(int, InterviewFeedback))();
BLDecision objBLDecision = new BLDecision();
int ReqCategoryID = 0;
if (Request.QueryString["ReqCategoryID"] != null)
ReqCategoryID = int.Parse(Request.QueryString["ReqCategoryID"].ToString());
CandIntDetails = objBLDecision.GetCandidatesforReqCategory(ReqCategoryID);
Repeater1.DataSource = CandIntDetails;
Repeater1.DataBind();
我应该从代码隐藏中使用,我可以不在aspx页面中执行 Eval('<% ....%>')
吗?
预先感谢您的帮助。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅用一台中继器是无法做到这一点的。由于容器内有容器,因此中继器内需要一个中继器:
You cannot do it with only one repeater. Since you have a container inside a container, you need a Repeater inside a repeater:
如果
CandIntDetails
是Dictionary>
,您需要从该集合中提取要用作数据源的特定集合。中继器。原因是您想要渲染InterviewFeedback
对象的集合,而CandIntDetails
则不是。CandIntDetails
可能看起来像这样:从您的帖子中不清楚内部或外部字典的键是什么,所以这是推测的。如果外部键是类别 ID(不确定为什么
GetCandidatesforReqCategory
会返回类似的内容),并且如果您不关心内部字典键,则可以像这样提取数据源:这将使您的数据源成为
InterviewFeedback
对象的直接集合。一旦这是您的数据源,您就可以Eval
来访问InterviewFeedback
对象的属性。If
CandIntDetails
is aDictionary<int, Dictionary<int, InterviewFeedback>>
, you need to extract from that the specific collection you want to use as the data source of your repeater. The reason why is because you want to render a collection ofInterviewFeedback
objects, whichCandIntDetails
is not.CandIntDetails
probably looks something like this:It's not clear from your post what the keys are for the inner or outer dictionaries, so this is speculative. If the outer key is the the category ID (not sure why
GetCandidatesforReqCategory
would return something like that), and if you don't care about the inner dictionary keys, you can extract your data source like this:That will make your data source a straight collection of
InterviewFeedback
objects. Once that's your data source, you canEval
to access the properties of theInterviewFeedback
objects.