2012-02-04 78 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

相關問題