7

会社の資産に関する階層情報を表示するasp.pageを作成しています。

データを取得するために、ラムダ式を使用しました。

            FASAssetInfoDataContext fasInfo = new FASAssetInfoDataContext();
        var data = from g in fasInfo.Asset_Informations
                          where g.Department.Substring(0, 3) == p
                          select g;
        Dictionary<string, Dictionary<string, List<info>>> branch = data.GroupBy(e => e.Location)
            .ToDictionary(g => g.Key,
            g => g.GroupBy(gl => gl.G_L_Asset_Acct_No)
                .ToDictionary(gl => gl.Key,
                gl => gl.Select(s => new info
                {
                    acqDate = s.Acquisition_Date,
                    asstNo = s.Co_Asset_Number,
                    classInfo = s.Class,
                    description = s.Description,
                    mfgSerialNo = s.Mfg_Serial_No,
                    deprThisRun = s.Depr_This_Run__Int_,
                    AcqValue = s.Acquisition_Value__Int_,
                    currentAccDepr = s.Current_Accum_Depr__Int_,
                    estLife = s.Est_Life__YYMM___Int_,
                    inServiceDate = s.Placed_In_Service_Date__Int_,
                    netBookValue = s.Current_Net_Book_Value__Int_,
                    oldAcqValue = s.Acquisition_Value__Tax_
                }).ToList()));

これで、最後に情報のリストが付いたネストされた辞書のセットができました。私の質問は、この情報をページ自体に表示するにはどうすればよいですか?私は最初のレベルを取得できますが、ネストされたリピーターを正しく機能させるのに苦労しています。使用するためのより良いコントロールがあれば、私はすべての耳です:)

ありがとう、

マルコ

4

3 に答える 3

15

ネストされたリピーターを実際に使用する必要がある場合は可能ですが、それを機能させることは特に明白ではありません。以下は機能します(簡潔にするために簡略化されています):

<asp:Repeater id="level1" OnItemDataBound="level1_ItemDataBound" ...>
  <ItemTemplate>
    <asp:Repeater id="level2" OnItemDataBound="level2_ItemDataBound" ...>
      <ItemTemplate>
        <asp:Repeater id="level3" OnItemDataBound="level3_ItemDataBound" ...>
        </asp:Repeater>
      </ItemTemplate>
    </asp:Repeater>
  </ItemTemplate>
</asp:Repeater>

コードビハインド:

protected void Page_Load(object sender, EventArgs e)
{
    Dictionary<string, Dictionary<string, List<info>>> branch = ...;
    level1.DataSource = branch;
    level1.DataBind();
}

protected void level1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    Dictionary<string, List<info>> data = (Dictionary<string, List<info>>)e.Item.DataItem;
    Repeater level2 = e.Item.FindControl("level2") as Repeater;
    level2.DataSource = data;
    level2.DataBind();
}

protected void level2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    List<info> data = (List<info>)e.Item.DataItem;
    Repeater level3 = e.Item.FindControl("level3") as Repeater;
    level3.DataSource = data;
    level3.DataBind();
}

protected void level3_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   // Bind properties from info elements in List<info> here
}
于 2009-05-30T00:02:48.173 に答える
9

ItemDataBound イベントを使用せずにこれを行うより良い方法があります。簡単にするために、2 レベルのリピーターを想定してみましょう。

<asp:Repeater id="level1" >
   <ItemTemplate>
     <asp:Repeater id="level2" 
          DataSource='<%# ((System.Collections.Generic.KeyValuePair<string,System.Collections.Generic.List<string>>)Container.DataItem).Value %>' >
      <ItemTemplate>
           <%# Container.DataItem %>
       </ItemTemplate>
      </asp:Repeater>
   </ItemTemplate>
 </asp:Repeater>

何らかの理由で ItemDataBound イベントが嫌いなので、通常はこの方法を好みます:)

于 2009-07-23T22:42:09.390 に答える
1

asp:TreeView?ネストされたデータセットをどのように処理するかはわかりませんが、表示するように設計されています。

于 2009-05-29T20:05:13.117 に答える