Reputation: 37
I have a repeater that works wonders.Now I need to verify if a record exists in a DB and if it does, do not show the dropdowns but other textboxes. If there is only 1 record, it works, but if it sees more than 1, it does not. Here is the code:
Main 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>
This is the backend:
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++;
What I am getting is kinda weird, because it does not fill all the options, say there are 2 items in the repeater, it just works on the first, but the second it looks like it does nothing, although if I debug, the values to fill in the boxes are correct, it gets them correctly from the DB. The last one in the backend, its inside a method I call in the Page_Load.
Thanks!
Upvotes: -1
Views: 21
Reputation: 37
Apparently, for some reason, the i++ was outside the foreach. Dumb mistake due to fatigue.
Upvotes: 0