This is a migrated thread and some comments may be shown as answers.

[Solved] Grid doesn't display correctly

1 Answer 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bob
Top achievements
Rank 1
Bob asked on 04 Feb 2011, 07:58 PM
I have a grid for viewing/editing lobbyists. When I call the Insert or Select function of the grid, they take me to the controller where I can insert or edit a lobbyist. One of the things associated with a lobbyist is a list of non-public funds expenditures the lobbyist made. I have a grid on the Insert/Select pages for the lobbyist where users can view/edit the non-public funds expenditures of the lobbyist.

The problem is that, I think because it is in a SelectLobbyist view, the grid for non-public expenditures doesn't display with Edit and Delete commands as I asked it to, but has Update and Cancel commands instead. Also, the grid appears to be directly editable, which I didn't think I asked for. The view:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<L5Lobbying.Models.ViewModels.Lobbyist_View>" %>
  
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Select A Lobbyist
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script src='<%= ResolveUrl("~/Scripts/jquery-1.4.1.js") %>' type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#save').click(function (event) {
                window.location = '<%= ResolveUrl("~/L5Lobbying/UpdateLobbyist") %>' + "?id=<%: Model.lobbyist.l5lob_id %>&name=" + $('#name').val() +
                    "&title=" + $('#title').val() + "&salary=" + $('#salary').val() + "&hours_worked=" + $('#hours_worked').val();
            });
            $('#npfexpbutton').click(function (event) {
                window.location = '<%= ResolveUrl("~/L5Lobbying/InsertNPFEXP") %>' + "?l5lob_id=<%: Model.lobbyist.l5lob_id %>";
            });
        });
    </script>
    <h2>
        Update a Lobbyist for
        <%: Model.agency.name %>
        for
        <%: Model.qtrend %></h2>
    <br />
    <table>
        <tr>
            <td style="text-align: right">
                Name
            </td>
            <td>
                <%: Html.TextBox("name", Model.lobbyist.name) %>
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
                Title
            </td>
            <td>
                <%: Html.TextBox("title", Model.lobbyist.title) %>
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
                Salary
            </td>
            <td>
                <%: Html.TextBox("salary", Model.lobbyist.salary.ToString("C")) %>
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
                Quarterly Hours
            </td>
            <td>
                <%: Html.TextBox("hours_worked", Model.lobbyist.hours_worked) %>
            </td>
        </tr>
    </table>
    <br />
    <%
        Html.Telerik().Grid<L5Lobbying.Models.l5npfexp>(Model.npfexps)
        .Name("grid1")
        .ToolBar(toolbar => toolbar.Template(() =>
            { %>
                <button id="npfexpbutton" class="toolbarbutton">Add Details of Non-Public Funds spent by <%: Model.lobbyist.name %></button>
            <% }))
        .DataKeys(keys => keys.Add(c => c.l5npf_id))
        .DataBinding(databinding => databinding
            .Server()
                .Select("SelectNPFEXP", "L5Lobbying", new { l5lob_id = Model.lobbyist.l5lob_id })
                .Insert("InsertNPFEXP", "L5Lobbying", new { l5lob_id = Model.lobbyist.l5lob_id })
                .Update("UpdateNPFEXP", "L5Lobbying", new { l5lob_id = Model.lobbyist.l5lob_id })
                .Delete("DeleteNPFEXP", "L5Lobbying", new { l5lob_id = Model.lobbyist.l5lob_id }))
        .Columns(c =>
        {
            c.Bound(o => o.edate).Format("{0:d}").Title("DATE").Width(90);
            c.Bound(o => o.bwac).Title("BWAC").Width(90);
            c.Bound(o => o.source).Title("SOURCE").Width(180);
            c.Bound(o => o.benefited).Title("BENEFITED").Width(180);
            c.Bound(o => o.purpose).Title("PURPOSE").Width(300);
            c.Bound(o => o.amount).Title("AMOUNT").Width(90).Format("{0:C}");
            c.Command(commands => 
            {
                commands.Edit();
                commands.Delete();
            }).Width(200).Title("COMMANDS");
        })
        .Pageable(p => p.PageSize(5)
                        .Style(GridPagerStyles.NextPreviousAndNumeric)
                        .Position(GridPagerPosition.Bottom))
        .Resizable(i => i.Columns(true))
        .Render();
    %>
    <br />
    <button id="save">
        UPDATE</button>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentHead" runat="server">
</asp:Content>
My question is, how can I get the grid to display as a "normal" (not editable) grid, even though it is in a "SelectLobbyist" page?

Thanks in advance,

Bob

1 Answer, 1 is accepted

Sort by
0
Bob
Top achievements
Rank 1
answered on 04 Feb 2011, 08:35 PM
I solved the problem by setting .Editable(o => o.Enable(false)).

This caused the grid to be the way I expected it.

Thanks,

Bob
Tags
Grid
Asked by
Bob
Top achievements
Rank 1
Answers by
Bob
Top achievements
Rank 1
Share this question
or