2012-02-04 75 views
0

我是.NET的新手,所以我很苦恼。我有一个内容页面,带有一个中继器控制。我有一个字典,这是一个Dictionary<string, Dictionary<int,[object]>>。我想中继器控件中的值从对象属性得到它 - 候选人姓名,将是object.CandName,候选人的手机将是object.Phone用字典<string,Dictionary <int,[object]绑定直放站>

我不知道如何使用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('<% ....%>')

在此先感谢您的帮助。

+0

您应该更准确地描述数据的格式。在某一时刻,你会说它是一个'Dictionary >',另一方面,你暗示你正在使用'Dictionary >'。字典包含什么,你想要你的输出看起来像什么?你希望按字典键分组的东西,还是想要访问特定键的所有值? – Jacob 2012-02-04 21:49:34

+0

它是:Dictionary(int,Dictionary(int,InterviewFeedback)); 我想要访问并显示特定键的所有值 - 每行都需要访问和显示所有值。 – 2012-02-05 10:10:44

回答

0

你不能只用一个中继器。既然你有一个容器内的容器,你需要一个中继器的中继器内:

<asp:Repeater ID="Repeater1" runat="server" EnableViewState="false"> 
<ItemTemplate> 
<div id="Div3"> 
    <table class="GridViewStyleNoBorder" width=750px cellspacing="0" border="0" > 
    <asp:Repeater ID="Repeater2" runat="server" DataSource='<%# Eval("Value")' > 
     <ItemTemplate> 
    <tr> 
    <td class="PagerStyle" colspan="4"> 
     <asp:Label ID="lblName" Runat="server" 
     Text='<%# Eval("Name") %>' /> 
    </td> 
    </tr> 

     </ItemTemplate> 
    </asp:Repeater> 


    </table> 
    </div> 
</ItemTemplate> 
</asp:Repeater> 
+0

感谢您的建议。我添加了另一个Repeater,但无法直接访问该值,因为Dictionary的值是一个业务对象。所以我在后面的代码上做了这个。我能够显示记录值。但它只显示一条记录。它共有3条记录,但显示第一行,但不显示其余记录。我应该把它放在什么地方,我错过了什么。 – 2012-02-05 19:19:34

0

如果CandIntDetailsDictionary<int, Dictionary<int, InterviewFeedback>>,您需要从您要为您的中继器的数据源使用的特定集合提取。原因是因为您要呈现InterviewFeedback对象的集合,其中CandIntDetails而不是CandIntDetails可能看起来是这样的:

{ 
    46: { 
     0: [InterviewFeedback], 
     1: [InterviewFeedback], 
     2: [InterviewFeedback] 
    } 
} 

这不是从你的职位是什么键是内部或外部的字典清楚,所以这是投机性的。如果外键是类别ID(不知道为什么GetCandidatesforReqCategory将返回类似的东西),如果你不关心内部字典键,你可以提取这样的数据源:

Repeater1.DataSource = CandIntDetails[ReqCategoryID].Values; 

这将使您的数据源成为InterviewFeedback对象的直接集合。一旦这是您的数据源,您可以Eval访问InterviewFeedback对象的属性。

+0

感谢您的建议。现在工作。 – 2012-02-07 08:55:24

相关问题