<ItemTemplate> <tr> <td><span><%#Eval("str4") %></span></td> </tr> </ItemTemplate> 以上是Repeater空間中一部分 下面是后天cs代碼,在Page_Load函數(shù)中的 protected Dictionary<string, string> dic = new Dictionary<string, string>(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { dic.Add("str1", "this is str1"); dic.Add("str2", "this is str2"); dic.Add("str3", "this is str3"); dic.Add("str4", "this is str4"); dic.Add("str5", "this is str5"); dic.Add("str6", "this is str6"); Repeater1.DataSource = dic; Page.DataBind(); } } 但是我在前臺調(diào)用Eval()函數(shù)出錯了。does not contain a property with the name 'str4' 是不是我前臺使用綁定表達式的時候,str4這個key值不在的?還是什么問題
1 回答

躍然一笑
TA貢獻1826條經(jīng)驗 獲得超6個贊
綁定方式不對,Dictionary 應(yīng)該使用><%#Eval("key")%>和<%#Eval("value")%>綁定.
例子:
<asp:Repeater ID="rptDemo" runat="server">
<HeaderTemplate>
<table>
<tr>
<td>demo</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("key")%>和<%#Eval("value")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
- 1 回答
- 0 關(guān)注
- 549 瀏覽
添加回答
舉報
0/150
提交
取消