I have a repeater that has a dropdownlist inside it. There is another separate dropdownlist outside the repeater. The user would select a value in this ddl, click a button, and the selected value would be populated in all the ddl's inside the repeater that are blank. Note: the ddl's have text for selectedvalue (not ints).

Unfortunately my code is not working.

My markup:

<asp:Repeater ID="AttendanceRepeater" runat="server" DataSourceID="AttendanceSqlDataSource" OnItemDataBound="AttendanceRepeater_ItemDataBound">
                <ItemTemplate>
                    <br />
                    <table>
                        <tr>
                            <td style="width: 50px"></td>
                            <td style="width: 300px">
                                <asp:Label ID="StudentNameLabel" runat="server" Text='<%# Eval("STUDENT_NAME") %>'></asp:Label>
                            </td>
                            <td style="width: 200px">
                                <asp:DropDownList ID="AttendStatusDropDownList" runat="server"
                                    SelectedValue='<%# Eval("ATTENDANCE_STATUS") %>'>
                                    <asp:ListItem Value="" Text=""></asp:ListItem>
                                    <asp:ListItem Value="ABSENTE" Text="Absent Excused"></asp:ListItem>
                                    <asp:ListItem Value="ABSENTU" Text="Absent Unexcused"></asp:ListItem>
                                    <asp:ListItem Value="CIN" Text="Chk In No (Absent)"></asp:ListItem>
                                    <asp:ListItem Value="CIY" Text="Chk In Yes (Present)"></asp:ListItem>
                                    <asp:ListItem Value="NR" Text="Attend Not Reqd"></asp:ListItem>
                                    <asp:ListItem Value="PRESENT" Text="Present"></asp:ListItem>
                                    <asp:ListItem Value="TM005" Text="Time Missed 005 Min"></asp:ListItem>
                                    <asp:ListItem Value="TM010" Text="Time Missed 010 Min"></asp:ListItem>
                                    <asp:ListItem Value="TM015" Text="Time Missed 015 Min"></asp:ListItem>
                                    <asp:ListItem Value="TM030" Text="Time Missed 030 Min"></asp:ListItem>
                                    <asp:ListItem Value="TM045" Text="Time Missed 045 Min"></asp:ListItem>
                                    <asp:ListItem Value="TM060" Text="Time Missed 1hr"></asp:ListItem>
                                    <asp:ListItem Value="TM075" Text="Time Missed 1hr 15mi"></asp:ListItem>
                                    <asp:ListItem Value="TM090" Text="Time Missed 1hr 30mi"></asp:ListItem>
                                    <asp:ListItem Value="TM105" Text="Time Missed 1hr 45mi"></asp:ListItem>
                                    <asp:ListItem Value="TM120" Text="Time Missed 2hr"></asp:ListItem>
                                    <asp:ListItem Value="TM135" Text="Time Missed 2hr 15mi"></asp:ListItem>
                                    <asp:ListItem Value="TM150" Text="Time Missed 2hr 30mi"></asp:ListItem>
                                    <asp:ListItem Value="TM165" Text="Time Missed 2hr 45mi"></asp:ListItem>
                                    <asp:ListItem Value="TM180" Text="Time Missed 3hr"></asp:ListItem>
                                    <asp:ListItem Value="TM195" Text="Time Missed 3hr 15mi"></asp:ListItem>
                                    <asp:ListItem Value="TM210" Text="Time Missed 3hr 30mi"></asp:ListItem>
                                    <asp:ListItem Value="TM225" Text="Time Missed 3hr 45mi"></asp:ListItem>
                                    <asp:ListItem Value="TM240" Text="Time Missed 4hr"></asp:ListItem>
                                    <asp:ListItem Value="TM255" Text="Time Missed 4hr 15mi"></asp:ListItem>
                                    <asp:ListItem Value="TM310" Text="Time Missed 4hr 30mi"></asp:ListItem>
                                    <asp:ListItem Value="TM325" Text="Time Missed 4hr 45mi"></asp:ListItem>
                                    <asp:ListItem Value="WD" Text="Withdrawn"></asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="AttendStatusValidator" runat="server"
                                    ErrorMessage="Required field" ControlToValidate="AttendStatusDropDownList">
                                </asp:RequiredFieldValidator>
                            </td>
                            <td style="width: 200px">
                                <asp:TextBox ID="CommentsTextBox" runat="server" TextMode="MultiLine" 
                                    Text='<%# Eval("COMMENTS") %>'></asp:TextBox>
                            </td>
                            <td>
<%--                                <asp:CheckBox ID="ChangeCheckBox" runat="server" Visible="true" />--%>
                                <asp:Label ID="PeopleCodeIdLabel" runat="server" Visible="false" Text='<%# Eval("PEOPLE_CODE_ID") %>'></asp:Label>
                                <asp:Label ID="AcademicYearLabel" runat="server" Visible="false" Text='<%# Eval("ACADEMIC_YEAR") %>'></asp:Label>
                                <asp:Label ID="AcademicTermLabel" runat="server" Visible="false" Text='<%# Eval("ACADEMIC_TERM") %>'></asp:Label>
                                <asp:Label ID="AcademicSessionLabel" runat="server" Visible="false" Text='<%# Eval("ACADEMIC_SESSION") %>'></asp:Label>
                                <asp:Label ID="EventIdLabel" runat="server" Visible="false" Text='<%# Eval("EVENT_ID") %>'></asp:Label>
                                <asp:Label ID="EventSubTypeLabel" runat="server" Visible="false" Text='<%# Eval("EVENT_SUB_TYPE") %>'></asp:Label>
                                <asp:Label ID="SectionLabel" runat="server" Visible="false" Text='<%# Eval("SECTION") %>'></asp:Label>
                                <asp:Label ID="TranAttendanceIdLabel" runat="server" Visible="false" Text='<%# Eval("TranAttendanceId") %>'></asp:Label>
                            </td>
                        </tr>
                    </table>
                    <br />
                </ItemTemplate>
            </asp:Repeater>

Code for the button: (Note the naming of the drop-downs. AttendanceStatusdropdownlist and AttendStatusAllDropDownList)

    protected void ApplyToAllButton_Click(object sender, EventArgs e)
{
    string defaultStatus = AttendStatusAllDropDownList.SelectedValue;

    foreach (RepeaterItem item in AttendanceRepeater.Items)
    {
        DropDownList ddl = (DropDownList)item.FindControl("AttendanceStatusDropDownList");
        if (string.IsNullOrWhiteSpace(ddl.SelectedValue))
        {
            //set the ddl to the value selected from the other ddl
            ddl.SelectedValue = defaultStatus;

        }
    }
    //Save changes to all
    SaveButton_Click(null, null);
}

The values are not populating in the drop-downs inside the repeater. I have searched google but cannot find anything specific to what I'm attempting. Any help would be much appreciated.

Thanks in advance. Pete

Related posts

Recent Viewed