【问题标题】:Two Controls in the same Column of the WebGridWebGrid同一列中的两个控件
【发布时间】:2013-08-17 10:35:26
【问题描述】:

我有一个包含 2 列的 webGrid,在第一列中我有日期,在第二列中我还有一个包含根据该日期的数据的 WebGrid。现在我想要的是在我拥有内部 WebGrid 的同一列中添加一个 Button。

我怎样才能做到这一点..我的内部 webgrid 包含 4 列,其中 2 列保存 DropdownList,另外两列保存文本框。 我想要在这个内部 WebGrid 之外但在 Main webGrid 内部的 Button。

我希望我很清楚..

这是我的代码

var grid = new WebGrid(Model, rowsPerPage: 100); 
@if (Model != null)
{

    @grid.GetHtml(htmlAttributes: new { id = "EmployeeTasksGrid" },
            tableStyle: "webGrid",
            headerStyle: "header",
            alternatingRowStyle: "alt",
            selectedRowStyle: "select",

columns:
  grid.Columns(
  grid.Column("TaskDate", "Task Date", style: ""),
    grid.Column("EmployeeTask", "Details", format: (resource) =>
    {

        WebGrid resParamGrid = new WebGrid(resource.EmpTasks);
        return resParamGrid.GetHtml(htmlAttributes: new { id = "EmployeeTasksSubGrid" },
            tableStyle: "webGrid subgrid",
    headerStyle: "header",

    selectedRowStyle: "select",

            columns: resParamGrid.Columns(
            resParamGrid.Column("Projects", "Project name",
    format:
        @<div class="taskname selector projects">
            @Html.DropDownList("Projects", null, "--Select--", new { id = "ddl_Projects" })
        </div>, style: "TaskNameWidth"),
     resParamGrid.Column("TaskNames", "Task name",
    format:
        @<div class="taskname selector tasks">
            <input type="hidden" class="hdnActivityId" name="ActivityId" value="@item.ActivityID"/>
            <input type="hidden" class="hdnRecordId" name="RecordID" value="@item.RecordID"/>
            <input type="hidden" class="hdnTaskID" name="TaskName" value="@item.TaskID"/>
            <input type="hidden" class="hdnProjectID" name="ProjectID" value="@item.ProjectID"/>
            <input type="hidden" class="hdnTaskDate" name="TaskDate" value="@item.TaskDate"/>
            <input type="hidden" class="hdnIsFreezed" name="IsFreezed" value="@item.IsFreezed"/>
            @Html.DropDownList("TaskNames", null, "--Select--", new { id = "ddl_Tasks", style = "tasksnew" })
        </div>, style: "TaskNameWidth"),
                       resParamGrid.Column("TaskDescription", "Task Description", format: @<text><textarea
                           rows="3" cols="3" class="taskDiss input">@item.TaskDescription</textarea>
    </text>, style: "col2Width"),
    resParamGrid.Column("Hours", "Hours", format: @<text><input type="text" id="Hours" value="@item.Hours" class="Hours input" onkeypress="javascript:return AllowDecimalNumber(this);"  />
    </text>, style: "col1Width"),
                       resParamGrid.Column("", style: "delete", format: @<text>
    <input type="button" class="delete-task input" />
    </text>, canSort: false)
            ),

            displayHeader: true

        );

   })

【问题讨论】:

    标签: c# asp.net-mvc-4 webgrid


    【解决方案1】:

    除非我遗漏了什么,否则我认为您可以在调用后立即为按钮附加 HTML,以便为第二个 WebGrid 生成 HTML。比如:

    return resParamGrid.GetHtml( ... ).ToHtmlString() + @"<input type=""button"" />"
    

    如果对类型很挑剔,您可能必须将字符串转换回IHtmlString

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 2013-09-20
      • 2010-12-21
      • 2013-10-04
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多