【发布时间】:2012-02-04 19:50:15
【问题描述】:
我是 .NET 的新手,所以我为此苦苦挣扎。我有一个带有中继器控件的内容页面。我有一个字典,它是Dictionary<string, Dictionary<int,[object]>>。我希望中继器控件内的控件值从对象属性中获取 - 候选名称,将是 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('<% ....%>') 吗?
提前感谢您的帮助。
【问题讨论】:
-
您应该更准确地描述数据的格式。有时您说它是
Dictionary<string, Dictionary<int, InterviewFeedback>>,而在另一种情况下,您暗示您正在使用Dictionary<int, Dictionary<int, InterviewFeedback>>。字典到底包含什么,你希望你的输出是什么样的?您想要按字典键对事物进行分组,还是想要访问特定键的所有值? -
它是: Dictionary(int, Dictionary(int, InterviewFeedback)) ;我想访问和显示特定键的所有值 - 每一行都需要访问和显示所有值。
标签: asp.net dictionary repeater eval bind