首页 新闻 会员 周边

在.NET企业级应用中循环取值

1
[已解决问题] 解决于 2017-07-08 13:49

索引(从零开始)必须大于或等于零,且小于参数列表的大小。

 foreach (XmlElement item in element.ChildNodes)
                {
                    sb.Append(string.Format(@"<tr class='odd gradeX'>
                                            <td>{0}</td>
                                            <td>{1}</td>
                                            <td class='hidden-480'>{2}</td>
                                            <td class='hidden-480'>{3}</td>
                                            <td class='center hidden-480'>{4}</td>
                                            <td><a href='/Home/SelAndDel/{5}'>删除</td>
                                        </tr>",
                                        item.Attributes["Id"].Value, item.InnerText,item.Attributes["Age"].Value,
                                        item.Attributes["Sex"].Value, item.Attributes["Phone"].Value)
                                        );
                }

报的错,在foreach 循环时有打断点item有取到这些值

TingZi_Unique的主页 TingZi_Unique | 初学一级 | 园豆:176
提问于:2017-07-06 17:13
< >
分享
最佳答案
2

 写了6个占位符你只给了5个参数。
想必你那个{5}是想给个ID吧?
item.Attributes["Id"].Value,
item.InnerText,
item.Attributes["Age"].Value,
item.Attributes["Sex"].Value,
item.Attributes["Phone"].Value,

item.Attributes["Id"].Value,

奖励园豆:5
Supreme` | 菜鸟二级 |园豆:229 | 2017-07-06 20:57
其他回答(2)
1

0-1-2-3-4-5 加起来等于6

item.Attributes["Id"].Value,

item.InnerText,

item.Attributes["Age"].Value,

item.Attributes["Sex"].Value,

item.Attributes["Phone"].Value

只有5行.那个1是谁点的.自己去掉..

吴瑞祥 | 园豆:29449 (高人七级) | 2017-07-06 18:09
0

{0}到{5} 但是你后面的参数不够6个

慧☆星 | 园豆:5640 (大侠五级) | 2017-07-07 09:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册