WebGrid的同一列中的两个控件

时间:2013-08-17 10:35:26

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

我有一个包含2列的webGrid,在第一列中我有Dates,在第二列中我还有一个WebGrid,其中包含根据该Date的数据。现在我想要的是我想在我的内部WebGrid的同一列中使用Button。

我怎样才能实现这一点。我的内部webgrid包含4列,其中2列包含DropdownList,另外2列包含文本框。 我希望Button在这个内部WebGrid之外,但在主webGrid中。

我希望我很清楚..

这是我的代码

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

        );

   })

1 个答案:

答案 0 :(得分:0)

除非我遗漏了某些内容,否则我认为您可以在调用之后立即将HTML添加到按钮中,以便为第二个WebGrid生成HTML。类似的东西:

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

如果字符串对类型很挑剔,则可能需要将字符串转换回IHtmlString