在模态弹出扩展器面板

时间:2016-12-08 15:55:34

标签: dynamically-generated tablerow modalpopupextender

我创建了一个Modal Popup Extender,其中一个面板包含一个html表。我通过在面板中动态添加表行来填充html表。表行已成功添加到html表中。在浏览器中修改表后,我需要通过按面板中的“保存”按钮来更新html表中的数据表。我可以使用findcontrol找到表控件,但不能引用任何动态添加的表行。行数返回0.任何建议都会有所帮助。代码

客户端

<ajax:ModalPopupExtender ID="LaborHourPopupExt" runat="server" PopupControlID="LaborHourPanel" TargetControlID="lnkFake"
            CancelControlID="CancelHourLaborEntry" BackgroundCssClass="modalBackground">
        </ajax:ModalPopupExtender>
        <asp:Panel ID="LaborHourPanel" runat="server" CssClass="modalTimeCardPopup" Style="display: none">
            <div class="header">
                Manage Hourly Labor
            </div>
            <div class="body">
                <asp:Table ID="HourLaborTable" runat="server" HorizontalAlign="Center">
                    <asp:TableRow runat="server"></asp:TableRow>
                </asp:Table>
            </div>
            <div class="footer">
                <asp:Button ID="SaveHourLaborEntry" runat="server" Text="Save" CssClass="yes" OnClick="UpdateTaskTable" />
                <asp:Button ID="CancelHourLaborEntry" runat="server" Text="Cancel" CssClass="yes" />
            </div>
        </asp:Panel>

protected void UpdateTaskTable(object sender, EventArgs e)
    {
        Table TaskTableCopy = (Table)FindControl("HourLaborTable");
        Response.Write(TaskTableCopy.Rows.Count);
        for (int i = 1; i < TaskTableCopy.Rows.Count; i++)
        {
            if (TaskTableCopy.Rows[i].Cells[2] != null & TaskTableCopy.Rows[i].Cells[3] != null & TaskTableCopy.Rows[i].Cells[4] != null & TaskTableCopy.Rows[i].Cells[5] != null)
            {
                DataRow[] CurrentTaskRow = CurrentProject.TaskTable.Select("[dtp:Id]=" + TaskTableCopy.Rows[i].Cells[0]);
                DataRow[] CurrentTechnicianRow = CurrentProject.TechnicianTable.Select("[dtp:Name] = " + CurrentTaskRow[0]["ResourceName"]);
                if (CurrentTaskRow[0] != null)
                {
                    CurrentTaskRow[0]["dtp:StartDate"] = TaskTableCopy.Rows[i].Cells[3] + "T" +TaskTableCopy.Rows[i].Cells[4];
                    CurrentTaskRow[0]["dtp:EndDate"] = TaskTableCopy.Rows[i].Cells[3] + "T" + TaskTableCopy.Rows[i].Cells[5];
                    CurrentTaskRow[0]["dtp:ResourceName"] = TaskTableCopy.Rows[i].Cells[2];
                    CurrentTaskRow[0]["dtp:ResourceID"] = CurrentTechnicianRow[0]["dtp:Id"];
                }
                else
                {
                    DataRow NewTaskRow = CurrentProject.TechnicianTable.NewRow();
                    NewTaskRow["dtp:Id"] = TaskTableCopy.Rows[i].Cells[0];
                    NewTaskRow["dtp:Name"] = TaskTableCopy.Rows[i].Cells[1];
                    NewTaskRow["dtp:StartDate"] = TaskTableCopy.Rows[i].Cells[3];
                    NewTaskRow["dtp:StartDate"] = TaskTableCopy.Rows[i].Cells[4];
                    NewTaskRow["dtp:ResourceID"] = CurrentTechnicianRow[0]["dtp:Id"];
                    CurrentProject.TaskTable.Rows.Add(NewTaskRow);
                }
            }
        }
    }

0 个答案:

没有答案