Repeater绑定一个List集合.List里面放的是Dictionary<string, object>这个泛型.在页面中怎么样取出泛型中的数据.
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
Dictionary<string, object> obj = new Dictionary<string, object>();
int Id = (int)reader["topicId"];
obj.Add("topicId",Id);
obj.Add("clickCount",(int)reader["clickCount"]);
obj.Add("replyCount",reader["replyCount"].ToString());
obj.Add("postName",reader["realname"].ToString());
obj.Add("title",reader["title"].ToString());
在页面中是这样的.<asp:Repeater ID="repeaterAnn" runat="server">
<ItemTemplate>
<tr class="zhiDing" id="tr01">
<td colspan="2">获取泛型的这个topicId</td>
<td><a href="#">获取泛型的这个postName</td>
</tr>
</ItemTemplate>
</asp:Repeater>取出上面红色字表示的数据.急求.
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
Dictionary<string, object> obj = new Dictionary<string, object>();
int Id = (int)reader["topicId"];
obj.Add("topicId",Id);
obj.Add("clickCount",(int)reader["clickCount"]);
obj.Add("replyCount",reader["replyCount"].ToString());
obj.Add("postName",reader["realname"].ToString());
obj.Add("title",reader["title"].ToString());
在页面中是这样的.<asp:Repeater ID="repeaterAnn" runat="server">
<ItemTemplate>
<tr class="zhiDing" id="tr01">
<td colspan="2">获取泛型的这个topicId</td>
<td><a href="#">获取泛型的这个postName</td>
</tr>
</ItemTemplate>
</asp:Repeater>取出上面红色字表示的数据.急求.
在数据绑定后做处理
like:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType== ListItemType.Item)
{
Label lbl=(Label)e.Item.FindControl("Label1");
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
Dictionary<string, object> obj = (Dictionary)e.Item.DataItem; lbl.text=obj.topicId;
} }
Dictionary <string, object> obj = (Dictionary)e.Item.DataItem;
这里可能有点错误大概意思就是这样思路是清晰的
<%# ((Dictionary)Eval(Dictionary的名字))["topicId"] %>