gpt4 book ai didi

c# - 如何使用带有字典列表的 asp.net 转发器?

转载 作者:太空宇宙 更新时间:2023-11-03 13:16:34 28 4
gpt4 key购买 nike

我有一个字典列表,我是这样创建的:

List<Dictionary<String, String>> _list = new List<Dictionary<string, string>>();
var q = from d in db.TT_DELIVERies
where d.DeliveryOrderNumber == donumber
select new { d.DeliveryId };
if (q.Count() > 0)
{
var qd = from d in db.TT_DELIVERY_REQUESTs
where d.DeliveryOrderId == q.ToList()[0].DeliveryId
select new { d.ItemDescription, d.PackageDescription };

Console.Write(qd.Count());
if (qd.Count() > 0)
{
foreach (var r in qd)
{
Dictionary<String, String> temp = new Dictionary<string, string>();
temp.Add("Name", r.ItemDescription);
temp.Add("Desc", r.PackageDescription);
_list.Add(temp);
}
}
}

我尝试像这样绑定(bind)中继器:

rptAddedDocs.DataSource = _list;
rptAddedDocs.DataBind();

这是我的中继器

<asp:Repeater ID="rptAddedDocs" runat="server">

<HeaderTemplate>
<table id="tblListAddedDocs" class="table table-condensed table-hover">
<thead>
<tr>
<th>No</th>
<th>Document Name</th>
<th>Quantity</th>
<th>UOM</th>
<th>Description</th>
<th></th>
</tr>
</thead>
</HeaderTemplate>

<ItemTemplate>
<tr>
<td>1</td>
<td><%# Eval("Name")%> </td>
<td>1 </td>
<td>Envlope </td>
<td><%#Eval("Desc")%> </td>
<td></td>
</tr>
</ItemTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>

但是我得到这样的错误:

DataBinding: 'System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' does not contain a property with the name 'Name'.

请帮助我如何正确使用带字典列表的中继器?

最佳答案

在您的 .aspx 文件中,您应该这样写:

<%#((System.Collections.Generic.Dictionary<string, string>)Container.DataItem)["Name"]%>

关于c# - 如何使用带有字典列表的 asp.net 转发器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25839706/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com