2011-01-09 17 views
1

ListView、ItemTemplate、Labelコントロールを使用して結果を配信する方法を教えてもらえますか?ここに私のコードは次のとおりです。ListView、ItemTemplate - 方法:結果テンプレートを提供する

<asp:ListView ID="lstViewResultsUpdate" runat="server" DataItem="Object"> 

<LayoutTemplate> 
    <h3>Listing</h3> 
    <blockquote> 
     <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>       
    </blockquote> 
</LayoutTemplate> 

<ItemSeparatorTemplate> 
    <hr /> 
</ItemSeparatorTemplate> 

<ItemTemplate> 

Label2 - <asp:Label runat="server" ID="Label2" Text='<%# GetAllValues(((Dictionary<string,List<string>>)Container.DataItem)["Test1"]) %>' /> 

<br/><br/><hr> 

Label3 - <asp:Label runat="server" ID="Label3" Text='<%# GetAllValues(((Dictionary<string,List<string>>)Container.DataItem)["Test2"]) %>' /> 

</ItemTemplate> 
</asp:ListView> 

codebedindは次のとおりです。

public string GetAllValues(object lst) 
    { 

     List<string> lstOfStr = (List<string>)lst; 
     //lstOfStr.Clear(); 

     string allValues = ""; 

     foreach (string str in lstOfStr) 

      allValues += "," + str; 

     return allValues; 
    } 

...と結果は次のとおりです。

Label2 - Label2item1, Label2item2, Label2item3, etc. 

<hr> 

Label3 - Label3item1, Label3item2, Label3item3, etc. 

結果を作成する方法:

Label2 - Label2item1 

<hr> 

Label3 - Label3item1 

Label2 - Label2item2 

<hr> 

Label3 - Label3item2 

Label2 - Label2item3 

<hr> 

Label3 - Label3item4 

答えて

0

コードビハインドの部分には問題があります:

public static IEnumerable<Article> GetArticles()  

{//データアクセスコードが示されていない}

コードを変換する方法このパブリック静的メソッドのコードへの私の最初のポストを形成しますか?

0

何かこれはうまくいくはずです。環境.Newlineは私が行く方法です。

allValues += Environment.NewLine + "," + str; 
関連する問題