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

Insert Only With Server Editing

9 Answers 321 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.
Bohemian
Top achievements
Rank 1
Bohemian asked on 30 Mar 2011, 10:48 PM
OK, so here is a snippet (below error) that is broken with the commented lines as they are...

The entire Error I get in debug mode (VS2010) is...
 
"System.NotSupportedException was unhandled by user code
  Message=The Update data binding setting is required by the edit command. Please specify the Update action or url in the DataBinding configuration.
  Source=Telerik.Web.Mvc
  StackTrace:
       at Telerik.Web.Mvc.UI.Grid`1.EnsureRequired()
       at Telerik.Web.Mvc.UI.ViewComponentBase.WriteHtml(HtmlTextWriter writer)
       at Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer)
       at Telerik.Web.Mvc.UI.ViewComponentBase.Render()
       at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.Render()
       at ASP.views_home_insert_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer) in (omitted for privacy)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Control.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in (omitted for privacy)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Control.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Page.Render(HtmlTextWriter writer)
       at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 
"

It works fine when the comments are removed...

What I am trying to accomplish is to have insert only capabilities and have the insert button appear as it does when the comments in this code are removed; this snippet is based on the telerik demo code at:
"http://demos.telerik.com/aspnet-mvc/grid/editingserverside'

my view snippet...
              <%               
                Html.Telerik().Grid<Namespace.Models.Data.MyModel>(Model)
                      .Name("Grid")
                      .DataKeys(keys =>
                      {
                        keys.Add(c => c.PK_ID);
                      })
                      .ToolBar(commands =>
                        {
                          commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" });
                        })
                      .DataBinding(dataBinding => dataBinding.Server()
                          .Insert("Insert", "Home/Insert", new { mode = GridEditMode.InLine, id = UId })
                          //.Update("Edit", "Home/Edit", new { mode = GridEditMode.InLine, id = UId }))
                          //.PrefixUrlParameters(false))
                          )
                      .Columns(columns =>
                      {
                        columns.Bound(c => c.DescriptionShort).Title("DescShort").Width(70);
                        columns.Bound(c => c.DescriptionLong).Title("DescLong").Width(100);

                        columns.Command(commands =>
                          {
                            commands.Edit().ButtonType(GridButtonType.Text); // NOTE: There is no .Insert() option here, without it I cannot do a insert, unless .Edit() is there.
                          }).Width(180).Title("Commands");
                      })
                      //.Editable(editing => editing.Mode(GridEditMode.InLine))
                      .Pageable(paging =>
                          paging.PageSize(10)
                              .Style(GridPagerStyles.NextPreviousAndNumeric)
                              .Position(GridPagerPosition.Bottom))
                      .Sortable()
                      .Scrollable()
                      .Render()
                      ;
              %>

Again, the point being I do not want to be able to Update only Insert and have the button that flips between edit/insert show up inline (but only insert)... why am I being forced to implement Update when I do not want it; only Insert?

9 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 31 Mar 2011, 07:49 AM
Hi,

The edit command is required when inserting in InLine mode as otherwise there will be no column/place to render the Insert/Cancel buttons. However, if you are using InForm or PopUp mode it is not required.

All the best,
Rosen
the Telerik team
0
Bohemian
Top achievements
Rank 1
answered on 31 Mar 2011, 02:12 PM
Why can't you guys have a Insert() method/command on its own; seems like something very desirable to have...

One-stop shopping instead of having to create additional forms/controls etc...

Is there someway to override or subclass this in or something?

Also there seems to be some detail missing in your example at:
http://demos.telerik.com/aspnet-mvc/Grid/EditingServerSide

in regards to InForm/PopUp as far as the sample code listed at this time goes...

E.G.: changing GridEditMode to InForm does not give me the rendering you have depicted at:
http://demos.telerik.com/aspnet-mvc/Grid/EditingServerSide

And it appears the samples always assume full CRUD is desired... the editing command is always there in your sample code...

Moreover, commenting out the editing lines; in the code above only gives me the ability to insert via the .ToolBar.Insert() method...
but no way to commit it...

0
Rosen
Telerik team
answered on 31 Mar 2011, 04:19 PM
Bohemian,

As I have mentioned in my  previous message, if there is no edit command column declared and InLine
mode is used there will be no buttons from which the insert form to be submitted. This is the reason the insert only functionality is not supported when in InLine mode.

Therefore, in order to have only insert functionality you should remove the edit command and set the edit mode to InForm. Similar to the following:

Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys =>
        {
          keys.Add(c => c.PK_ID);
        })
        .ToolBar(commands =>
          {
            commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" });
          })
        .DataBinding(dataBinding => dataBinding.Server()
            .Insert("Insert", "Home/Insert", new { mode = GridEditMode.InLine, id = UId })
            )
        .Columns(columns =>
        {
          columns.Bound(c => c.DescriptionShort).Title("DescShort").Width(70);
          columns.Bound(c => c.DescriptionLong).Title("DescLong").Width(100);
        })
        .Editable(editing => editing.Mode(GridEditMode.InForm))

Best wishes,
Rosen
the Telerik team
0
Bohemian
Top achievements
Rank 1
answered on 31 Mar 2011, 04:54 PM
IF I understand you correctly this should work but it does not...

              <%               
                Html.Telerik().Grid<Namespace.Data.Models.MyModel>(Model)
                      .Name("Grid")
                      .DataKeys(keys =>
                      {
                        keys.Add(c => c.PK_ID);
                      })
                      .ToolBar(commands =>
                        {
                          commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" });
                        })
                      .DataBinding(dataBinding => dataBinding.Server()
                          .Insert("Insert", "Home/Insert", new { mode = GridEditMode.InForm, id = UId })
                          //.Update("Edit", "Home/Edit", new { mode = GridEditMode.InLine }))
                          //.PrefixUrlParameters(false)                                                    
                          )
                      .Columns(columns =>
                      {
                        columns.Bound(c => c.DescriptionShort).Title("DescShort").Width(70);
                        columns.Bound(c => c.DescriptionLong).Title("DescLong").Width(100);

                        //columns.Command(commands =>
                        //  {
                        //    commands.Edit().ButtonType(GridButtonType.Text);
                        //  }).Width(180).Title("Commands");
                      })
                      .Editable(editing => editing.Mode(GridEditMode.InForm))
                      .Pageable(paging =>
                          paging.PageSize(10)
                              .Style(GridPagerStyles.NextPreviousAndNumeric)
                              .Position(GridPagerPosition.Bottom))
                      .Sortable()
                      .Scrollable()
                      .Render()
                      ;
              %>
0
Rosen
Telerik team
answered on 01 Apr 2011, 07:50 AM
Hello,

 I have attached a small sample which demonstrates the approach I have described. Please take a look maybe I'm missing something obvious.

Regards,
Rosen
the Telerik team
0
Bohemian
Top achievements
Rank 1
answered on 04 Apr 2011, 11:21 PM
Does not work with Telerik.Web.Mvc Version 2010.2.825.235
And
System.Web.Mvc.dll Version 2.0.0.0

E.G.: MVC2

And there are a significant amount of breaking changes, deprecated functionality, etc., between the two of them making it less than desirable to go to MVC3 from MVC2 on both the Telerik and Microsoft side at this time...

Can't even buy a stinking MVC3 book yet...

How about a MVC2 sample?

thanks in advance.

0
Matthew
Top achievements
Rank 1
answered on 24 May 2012, 07:32 PM
I got this to work with In-Line editing:

function GridNotes_onEdit(e) {
        $('#Content').after("<a class='t-button t-grid-cancel t-button-icon' href='#'><span class='t-icon t-cancel'/></a>")
            .after("<a class='t-button t-grid-insert t-button-icon' href='#'><span class='t-icon t-insert'/></a>");
    }


Now this was when I only had one column that was being inserted.  So if you have more than one column, you might need to customize it to your specifications.  As well, it worked inside a detail view grid.  Hope this helps and sorry if this is too late...
0
Michael
Top achievements
Rank 1
answered on 20 Sep 2012, 03:27 PM
I know this is an old posting, and all, but I have a simple solution... hide the Edit button...
Add a Hide function to the OnRowDataBound event...

.ClientEvents(events => events.OnRowDataBound("hideEditButton"))

    <script type="text/javascript">
        function hideEditButton() {
            $('.t-grid-edit').hide();
        }
    </script>

0
Michel Corbin
Top achievements
Rank 1
answered on 11 Jan 2013, 04:50 PM
Michael, you are the hero of my day!!!

Thank you very much.

I'm just wondering to know why no one at Telerik have thought about this super simple solution.
Tags
Grid
Asked by
Bohemian
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Bohemian
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Michel Corbin
Top achievements
Rank 1
Share this question
or