我无法对下表格式的数据进行分组,并尝试按第二种表格格式提及对数据进行分组
legacy subid converted licPart count
Ent 100 EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL AC CE E-LTU LIC-CP-EN-100 100
Ent 100 EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL OB USR E-LTU LIC-CP-EN-100 100
Ent 100 EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL OG EP E-LTU LIC-CP-EN-100 100
Ent 100 EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL AC CE E-LTU LIC-CP-EN-100 100
Ent 100 EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL OB USR E-LTU LIC-CP-EN-100 100
Ent 100 EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL OG EP E-LTU LIC-CP-EN-100 100
Ent 1K EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL AC CE E-LTU LIC-CP-EN-1K 1000
Ent 1K EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL OB USR E-LTU LIC-CP-EN-1K 1000
Ent 1K EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL OG EP E-LTU LIC-CP-EN-1K 1000
我正在尝试获取如下所示的数据,以便进一步分配到转发器以显示信息
Ent 100 EP Lic E-LTU 7ks7gp-qc42sn-g7zk0q-7pzmb7-xdp6yb NL AC CE E-LTU LIC-CP-EN-100 100
NL OB USR E-LTU
NL OG EP E-LTU
Ent 100 EP Lic E-LTU NL AC CE E-LTU LIC-CP-EN-100 100
NL OB USR E-LTU
NL OG EP E-LTU
Ent 1K EP Lic E-LTU NL AC CE E-LTU LIC-CP-EN-1K 1000
NL OB USR E-LTU
NL OG EP E-LTU
我在rowdatabound事件期间尝试使用网格视图并且其工作正常,但我无法使用转发器获得相同的效果。我确信在将数据分配给转发器之前我们需要对数据进行分组
但我不知道如何将数据分组如上所述
这是我的转发器代码
<asp:Repeater ID="RepeaterEnterprise" runat="server" OnItemDataBound="ItemBound">
<HeaderTemplate>
<table>
<tr>
<th>Avaialable Endpoints
</th>
<th>Converted Endpoints
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<table>
<tr>
<td>
<asp:TextBox runat="server" ID="txtAvaialble" Text='<%#Eval("LicenseCount") %>' ReadOnly="true">
</asp:TextBox>
</td>
<td>
<asp:TextBox runat="server" ID="txtConverted" Text='' ReadOnly="true">
</asp:TextBox>
</td>
<td>
<tr>
<td>
<asp:Label ID="lblcount" runat="server" Text='<%# Eval("Converted") %>'></asp:Label>
</td>
<td>25*
</td>
</tr>
</table>
<table>
<tr>
<td>
<asp:TextBox runat="server" ID="txtEndpoints" Text=''>
</asp:TextBox>
</td>
<td>
<asp:TextBox runat="server" ID="txtTotalEndPoints" Text='' ReadOnly="true">
</asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td>
</td>
</tr>
</SeparatorTemplate>
<AlternatingItemTemplate>
<table>
<tr>
<td>
<asp:TextBox runat="server" ID="txtAvaialbleEndPoints" Text='<%#Eval("Count") %>' ReadOnly="true">
</asp:TextBox>
</td>
<td>
<asp:TextBox runat="server" ID="txtConvertedEndPoints" Text='' ReadOnly="true">
</asp:TextBox>
</td>
<td>
<tr>
<td>
<asp:Label ID="lblcountryname" runat="server" Text='<%# Eval("Converted") %>'></asp:Label>
</td>
<td>25*
</td>
</tr>
</table>
<table>
<tr>
<td>
<asp:TextBox runat="server" ID="txtEndpoints" Text=''>
</asp:TextBox>
</td>
<td>
<asp:TextBox runat="server" ID="txtTotalEndPoints" Text='' ReadOnly="true">
</asp:TextBox>
</td>
</tr>
</table>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
任何人都可以对此解决方案有任何想法如何进行分组吗?
答案 0 :(得分:2)
分组规则在您的初始问题中并不明显,但根据您的意见,我认为您需要
我想你有一些类似于那些下面的类
public class InputModel
{
public string legacy { get; set; }
public string subid { get; set; }
public string converted { get; set; }
public string licPart { get; set; }
public string count { get; set; }
}
public class OutputModel
{
public string legacy { get; set; }
public string subid { get; set; }
public IList<string> list { get; set; }
public string licPart { get; set; }
}
在其他解决方案中,您可以依赖reducer/fold/aggregate方法,为此,C#可以使用可枚举的 .Aggregate (在here中可以找到一些很好的示例)孔)
var seed = new List<OutputModel>();
var outcome = records
.Aggregate(seed, (results, current) =>
{
var query = from result in results
where result.legacy == current.legacy
&& (result.list == null
|| !result.list.Contains(current.converted))
select result;
var output = query.FirstOrDefault();
if (output == null)
{
output = new OutputModel
{
legacy = current.legacy,
subid = current.subid,
licPart = current.licPart,
list = new List<string>
{
current.converted
}
};
results.Add(output);
}
else
{
output.list.Add(current.converted);
}
return results;
});
会给你这个
修改强>
请求请参阅下面一种将表映射到输入记录集合的方法
public static class Extensions
{
public static IEnumerable<InputModel> Map(this DataTable instance)
{
foreach (DataRow row in instance.Rows)
{
yield return new InputModel
{
legacy = (string)row[0],
subid = (string)row[1],
converted = (string)row[2],
licPart = (string)row[3],
count = (string)row[4],
};
}
}
}