2013-07-18 70 views
0

我正嘗試使用中繼器顯示其子類別和子子類別的購物類別..數據是綁定的,但未顯示..任何人都可以幫助原因嗎? 這裏是我的代碼:使用中繼器顯示數據時遇到的困難

.aspx文件

<asp:Repeater ID="CategoryRepeater" runat="server" OnItemDataBound="CategoryRepeater_OnItemDataBound"> 
    <ItemTemplate> 
     <a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>'<%#Eval("CategoryName") %>></a><br /> 
     <asp:Repeater ID="SubCategoryRepeater" runat="server" OnItemDataBound="SubCategoryRepeater_OnItemDataBound"> 
      <ItemTemplate> 
        <a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>&SubCategoryId=<%#Eval("SubCategoryId") %>'<%#Eval("SubCategoryName") %>></a><br /> 
       <asp:Repeater ID="SubSubCategoryRepeater" runat="server"> 
        <ItemTemplate> 
         <a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>&SubCategoryId=<%#Eval("SubCategoryId") %>&SubSubCategoryId=<%#Eval("SubSubCategoryId") %>'<%#Eval("SubSubCategoryName") %>></a><br /> 
        </ItemTemplate> 
       </asp:Repeater> 
      </ItemTemplate> 
     </asp:Repeater> 

    </ItemTemplate> 
</asp:Repeater> 

C#代碼:

protected void CategoryRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e) 
{ 
    if ((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem)) 
    { 
     DataRowView dataItem = e.Item.DataItem as DataRowView; 
     int categoryId = Convert.ToInt32(dataItem["CategoryId"]); 
     Repeater rp = (Repeater)e.Item.FindControl("SubCategoryRepeater"); 
     ds = us.SelectSubCategories(categoryId); 
     rp.DataSource = ds; 
     rp.DataBind(); 
    } 
} 

protected void SubCategoryRepeater_OnItemDataBound(object sender, RepeaterItemEventArgs e) 
{ 
    if ((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem)) 
    { 
     DataRowView dataItem = e.Item.DataItem as DataRowView; 
     int SubCategoryId = Convert.ToInt32(dataItem["SubCategoryId"]); 
     Repeater rp1 = (Repeater)e.Item.FindControl("SubSubCategoryRepeater"); 
     ds1 = us.SelectSubSubCategories(SubCategoryId); 
     rp1.DataSource = ds1; 
     rp1.DataBind(); 
    } 
} 

回答

1

檢查你的源代碼,以確保沒有被輸出到頁面。我認爲你只是在錨標籤內部呈現類別名稱。

下面是相同的代碼與簡化,看看是怎麼回事

<a href='Clothing.aspx?CategoryId={catid}'{name}></a> 

應該是evals:

<a href='Clothing.aspx?CategoryId={catid}'>{name}</a> 

<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>'><%#Eval("CategoryName") %></a> 

同樣的錯誤,在全部完成三個地點。

+0

對不起,我同時發佈。這應該是正確答案,Manbir。 – LUKE

+0

Thanx很多.. :) – Manbir

1

我認爲所有的代碼都是正確的,但是你的輸出是錯誤的。

你這樣做:

<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>&SubCategoryId=<%#Eval("SubCategoryId") %>'<%#Eval("SubCategoryName") %>></a><br /> 

但它需要

<a href='Clothing.aspx?CategoryId=<%#Eval("CategoryId") %>&SubCategoryId=<%#Eval("SubCategoryId") %>'><%#Eval("SubCategoryName") %></a><br /> 

注意到我感動 '>' 背後<%#的eval( 「SubCategoryName」)%>

+0

是啊.. thanx ..我明白了.. :) – Manbir

相關問題