asp.net - ASP 中继器未填充所有项目
问题描述
我有一个可以创造奇迹的中继器。现在我需要验证数据库中是否存在记录,如果存在,则不要显示下拉列表,而是显示其他文本框。如果只有 1 条记录,它可以工作,但如果它看到多于 1 条,它不会。这是代码:
主要ASPX:
<asp:Repeater ID="repStudents" runat="server">
<ItemTemplate>
<asp:DropDownList ID="reasonStd" runat="server">
<asp:ListItem Enabled="true" Text="Select Reason" Value="-1"></asp:ListItem>
OPTIONS...
</asp:DropDownList>
<asp:TextBox ID="reasonLabel" runat="server" Visible="false"></asp:TextBox>
<span>
<asp:TextBox ID="dateForStudents" type="date" runat="server" CssClass="form-control"></asp:TextBox>
<asp:TextBox ID="dateLabel" runat="server" Visible="false"></asp:TextBox>
</span>
这是后端:
List<ASF.FinanceCenter.Entity.Student> dt = dbStudents.GetAllByFamilyId(int.Parse(lFamilyId.Text)); <--- This fills the same number as repeater
int i = 0;
DropDownList students;
TextBox txtStudents, lastDay, reason;
foreach (ASF.FinanceCenter.Entity.Student studentinos in dt)
{
students = repStudents.Items[i].FindControl("reasonStd") as DropDownList;
txtStudents = repStudents.Items[i].FindControl("dateForStudents") as TextBox;
lastDay = repStudents.Items[i].FindControl("dateLabel") as TextBox;
reason = repStudents.Items[i].FindControl("reasonLabel") as TextBox;
reason.Visible = true;
students.Visible = false;
txtStudents.Visible = false;
lastDay.Visible = true;
lastDay.Text = GetDataLastDay(studentinos.Id.ToString());
reason.Text = GetDataReason(studentinos.Id.ToString());
}
i++;
我得到的有点奇怪,因为它没有填写所有选项,比如中继器中有 2 个项目,它只适用于第一个项目,但第二个项目看起来什么也没做,尽管如果我调试,值填写框是正确的,它从数据库中正确获取它们。后端的最后一个,它在我在 Page_Load 中调用的方法中。
谢谢!
解决方案
显然,出于某种原因, i++ 在 foreach 之外。由于疲劳导致的愚蠢错误。
推荐阅读
- ios - 我想使用 2 个按钮在同一个 ViewController 上显示两个图像
- java - 路径变量导致 404
- c# - 在 wpf 中仅禁用所有者窗口
- jenkins - git merge 如何用于多分支管道?
- javascript - 当我不再需要这个 `await nextEvent(element, 'mousemove')` 模式时,如何清理它?
- php - 有没有办法将所有模式放在一个文件中并在整个网站上触发它们?
- node.js - 错误:无法查找视图“感谢您加入我们的等候名单!” 在视图目录“C:\Users\mchio\JoinUs\views”中
- yocto - agl-demo-platform 的 do_rootfs 失败
- ios - 如何在由 Firebase 实时数据库提供支持的 iOS 应用中观察对话?
- c++ - 从森林中构建 n 叉树