locked
dynamic column headers in a webgrid RRS feed

  • Question

  • User379720387 posted

    I am display some volume data in a webgrid column and I would like the header to display the units used.

    Not much luck finding something on the web either.

    var headertxt = "Volume (" + headerunits+ ")";
    
    grid.Column("strDataVolume",
                            header : "@headertxt",
                            style: "col3",
                            format: @<text>
                                <span id="strdatavolume" class="display-mode">@item.strDataVolume</span>
                                @Html.TextBox("strDataVolume", item.strDataVolume, new { @class = "edit-mode"})
                            </text>)
    Wednesday, July 15, 2015 6:52 PM

Answers

  • User-821857111 posted

    You almost have it:

    var headertxt = "Volume (" + headerunits+ ")";
    grid.Column("strDataVolume",
                            header : headertxt,
                            style: "col3",
                            format: @<text>
                                <span id="strdatavolume" class="display-mode">@item.strDataVolume</span>
                                @Html.TextBox("strDataVolume", item.strDataVolume, new { @class = "edit-mode"})
                            </text>)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2015 9:03 AM
  • User-821857111 posted

    The headerunits variable must be a dynamic type. Explicitly type it as a string:

    string headertxt = "Volume (" + headerunits+ ")";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2015 3:01 PM

All replies

  • User2024324573 posted

    Please refer to this thread: http://stackoverflow.com/questions/14139513/how-to-set-dynamic-column-header-in-webgrid

    Hope this will help.

    Wednesday, July 15, 2015 9:12 PM
  • User379720387 posted

    That is an MVC  application, cannot really tell if that is applicable to Web Pages.

    Thursday, July 16, 2015 8:16 AM
  • User-821857111 posted

    You almost have it:

    var headertxt = "Volume (" + headerunits+ ")";
    grid.Column("strDataVolume",
                            header : headertxt,
                            style: "col3",
                            format: @<text>
                                <span id="strdatavolume" class="display-mode">@item.strDataVolume</span>
                                @Html.TextBox("strDataVolume", item.strDataVolume, new { @class = "edit-mode"})
                            </text>)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2015 9:03 AM
  • User379720387 posted

    I tried that.

    VS seems to accept the "head: headertext,"

    But then immediately a squigly shows up underneath the colon of format:

    "Cannot use an expression of type 'lambda expression' as an argument to a dynamically dispatched operation"

    I did find your blog entry on this subject.

    Thursday, July 16, 2015 9:31 AM
  • User-821857111 posted

    The headerunits variable must be a dynamic type. Explicitly type it as a string:

    string headertxt = "Volume (" + headerunits+ ")";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2015 3:01 PM