【问题标题】:ASP.NET form that shows a variable amount of rows and columns for checkbox inputs为复选框输入显示可变数量的行和列的 ASP.NET 表单
【发布时间】:2017-10-18 04:47:37
【问题描述】:

我正在尝试编写允许我执行以下操作的代码:

  • 选择一个项目为其编写任务。
  • 在单击按钮时添加一个新的输入行。
  • 写出一个任务 “窗户清洁”
  • 选择一个任务类型 “清洁”
  • 写出执行任务的最长时间(分钟)
  • 根据项目 开始日期和结束日期,用复选框显示项目持续时间(以月为单位)
  • 选中应在哪个月份执行任务的复选框
  • 点击按钮即可添加新的输入行。
  • 最后将所有这些保存到数据库中

How I envision the screen looking like (X's are checked boxes)

现在我确实对如何解决大部分问题有了相当多的了解。但是我真的迷失了如何绘制表格的部分。我会很感激一些指向正确方向的指针。

简单控制器:

public TaskplannerController : Controller
{
    [HttpGet]
    public ActionResult Index()
    {
        var model = new TaskplannerViewModel();
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(TaskplannerViewModel model)
    {
        model.ProjectDurationInMonths = model.GetProjectDuration();
        return View(model);
    }
}

使用 ViewModel:

public class TaskplannerViewModel
{
    public IEnumerable<SelectListItem> Types;
    public IEnumerable<SelectListItem> Projects;
    public IEnumerable<DateTime> ProjectDurationInMonths;

    public int Id { get; set; }
    public int ProjectId { get; set; }
    public string TaskDescription { get; set; }
    public int TypeId { get; set; }
    public int MaxTimeInMinutes { get; set; }     

    public EditPoTaakViewModel()
    {
        PopulateSelectLists();
    }  

    private void PopulateSelectLists()
    {
        var taskType = new TaskType();
        TaskTypes = type.GetAll();

        var project = new Project();
        Projects = project.GetAll();
    }

    public IEnumerable<DateTime> GetProjectDuration()
    {
        var project = new Project();
        var selectedProject = project.Get(ProjectId);
        DateTime startDate = selectedProject.StartDate;
        DateTime endDate= selectedProject.endDate;

        while(startDate <= endDate)
        {
            yield return startDate;
            startDate = startDate.AddMonths(1);
        }
    }
}

【问题讨论】:

  • 使用jquery或javascript绘制表单

标签: c# jquery asp.net forms multiple-columns


【解决方案1】:

我认为 asp 中继器可能是你需要的。

它看起来像这样:

<asp:Repeater runat="server">
    <HeaderTemplate>
        <table>
           <tr class="Headertemplate">                                                                               
              <th style="display:none;">ID</th>            
              <th>Task</th>
              <th>Type</th>
              <th>Max time in minutes</th>
              <th>Month</th> 
           </tr>            
    </HeaderTemplate>
    <ItemTemplate>
           <tr class="Itemtemplate">                                                             
              <td><asp:Label Text="text" runat="server" /></td>
              <td>
                  <asp:DropDownList runat="server">
                      <asp:ListItem Text="text1" />
                      <asp:ListItem Text="text2" />
                  </asp:DropDownList>
              </td>
              <td><asp:TextBox runat="server" /></td>
              <td><asp:CheckBox Text="text" runat="server" /></td>
              <td></td>
           </tr>
    </ItemTemplate>        
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>

【讨论】:

    猜你喜欢
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多