这是中继器代码的快照。我在获取所有值时遇到问题。结果我的“中继器”只打印集合中的第一个元素。
<asp:Repeater ID="repeatAdministrators" OnItemDataBound="repeatAdministrators_ItemDataBound" runat="server">
<HeaderTemplate>
<tr>
<td class="formLabel">
Administrators:
</td>
<td class="formInputText">
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtAdministrators" runat="server" MaxLength="50" Enabled="False"></asp:TextBox><br />
</ItemTemplate>
<FooterTemplate>
</td> </tr>
<tr>
</FooterTemplate>
</asp:Repeater>
这里是我想更改集合中读取索引的代码。AdminsEnumerator.MoveNext();
没有按我的预期工作。添加类似的东西int t; i++; StringCollection[i]
很烦人。有更简单的解决方案吗?
protected void repeatAdministrators_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
TextBox txtAdministrators = e.Item.FindControl("txtAdministrators") as TextBox;
StringEnumerator AdminsEnumerator = Computer.Administrators.GetEnumerator();
AdminsEnumerator.MoveNext();
txtAdministrators.Text = AdminsEnumerator.Current;
}
}