嵌套字典到嵌套转发器 asp.net c#

nested dictionary to nested repeater asp.net c#(嵌套字典到嵌套转发器 asp.net c#)

本文介绍了嵌套字典到嵌套转发器 asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个 asp.page,它将显示有关公司资产的分层信息.

I'm making an asp.page that will display hierarchical information about company assets.

为了获取数据,我使用了 lambda 表达式:

To grab the data I used a lambda expression:

            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()));

所以我现在有一组嵌套的字典,最后有一个信息列表.我的问题是如何最好地在页面上显示这些信息?我可以达到第一级,但一直在努力使嵌套中继器正常运行.如果有更好的控制来使用我全神贯注:)

So I now have a nested set of dictionaries with a list of information at the end. My question is how do I best display this information on the page itself? I can get the first level but have been struggling to get the nested repeater to function properly. If there is a better control to use I'm all ears :)

谢谢,

马可

推荐答案

如果你确实需要使用嵌套的转发器,这是可能的,但让它工作并不是特别明显.以下将起作用(为简洁起见进行了简化):

If you do indeed need to use nested repeaters, its possible, but getting it working isn't particularly obvious. The following would work (simplified for brevity):

<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
}

这篇关于嵌套字典到嵌套转发器 asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:嵌套字典到嵌套转发器 asp.net c#

基础教程推荐