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

[Solved] Insert in a DetailsView

2 Answers 204 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.
Matthew
Top achievements
Rank 1
Matthew asked on 13 Oct 2010, 10:00 AM
My code looks like:
<% Html.Telerik()
           .Grid<Mod.Data.Streampac.AgendaPoint>(this.Model)
           .Name(string.Format("AgendaPointGrid_{0}", 0))
           .DetailView(detailView => detailView.Template(a =>
       {
           Html.Telerik()
                 .Grid<Mod.Data.Streampac.Polls_AgendaPoint>(a.Polls_AgendaPoints)
                 .Name(string.Format("PollsGrid_{0}", a.AgendaPointID))
                 .ToolBar(commands => commands.Insert())
                 .DataBinding(dataBinding =>
                      {
                          dataBinding.Server()
                              .Select("EditPoll", "Polls", new { micrositeId = worky.MicrositeId, eventId = worky.Event.EventID })
                              .Insert("InsertPoll", "Polls", new { micrositeId = worky.MicrositeId, eventId = worky.Event.EventID, agendaId = a.AgendaPointID })
                              .Delete("DeletePoll", "Polls", new { micrositeId = worky.MicrositeId, eventId = worky.Event.EventID, agendaId = a.AgendaPointID })
                              .Update("UpdatePoll",
                                "Polls",
                                new { micrositeId = worky.MicrositeId, eventId = worky.Event.EventID, agendaId = a.AgendaPointID });
 
                      })
                 .Columns(columns =>
                 {
                     columns.Bound(e => e.PollID).Width(105).ReadOnly();
                     columns.Bound(e => e.Poll.PollTitle).Width(130).Encoded(false);
                     columns.Bound(e => e.Poll.PollDescription).Width(400).Encoded(false);
                     columns.Command(commands =>
                     {
                         commands.Edit();
                         commands.Delete();
                     }).Width(50);
 
                 })
                 .Sortable(sorting => sorting
                      .OrderBy(sortOrder => sortOrder.Add(o => o.PollID).Descending()))
                 .Filterable()
                 .Pageable()
                 .Resizable(resize => resize.Columns(true))
                 .DataKeys(keys =>
                 {
                     keys.Add(e => e.PollID).RouteKey("id");
                     //keys.Add(e => e.Speaker).RouteKey("speaker");
                 })
                  
//--------------------------------  Poll Questions -----------------------------------------
                  
 
                 .DetailView(detailViewPollQ => detailViewPollQ.Template(x =>
       {
          // if (x.Poll.PollQuestions.Count() != 0)
          // {
               Html.Telerik()
                     .Grid<Mod.Data.Streampac.PollQuestion>(x.Poll.PollQuestions)
                     .Name(string.Format("PollQuestionsGrid_{0}", x.AgendaPointID))
                     .ToolBar(commands => commands.Insert())
                     .DataBinding(dataBinding =>
                          {
                              dataBinding.Server()
                                  .Select("EditQuestion", "Polls", new { micrositeId = worky.MicrositeId, eventId = worky.Event.EventID })
                                  .Insert("InsertQuestion", "Polls", new { micrositeId = worky.MicrositeId, eventId = worky.Event.EventID })
                                  .Delete("DeleteQuestion", "Polls", new { micrositeId = worky.MicrositeId, eventId = worky.Event.EventID })
                                  .Update("UpdateQuestion",
                                    "Polls",
                                    new { micrositeId = worky.MicrositeId, eventId = worky.Event.EventID, agendaId = a.AgendaPointID });
 
                          })
 
                     .Columns(columns =>
                     {
                         columns.Bound(v => v.PollQuestionID).Width(105).ReadOnly();
                         columns.Bound(v => v.QuestionText).Width(400).Encoded(false);
 
                         columns.Command(commands =>
                         {
                             commands.Edit();
                             commands.Delete();
                         }).Width(50);
 
                     })
 
                     .Sortable()
                     .Filterable()
                     .Pageable()
                     .Resizable(resize => resize.Columns(true))
                     .DataKeys(keys =>
                     {
                         keys.Add(v => v.PollQuestionID).RouteKey("questionId");
                         //keys.Add(e => e.Speaker).RouteKey("speaker");
                     })
 
                     .Render();
 
         //  }
       }))
            .Render();
        }))
                 .RowAction(row =>
                 {
                     if (row.Index == 0)
                     {
                         row.DetailRow.Expanded = true;
                     }
                     else
                     {
                         var requestKeys = Request.QueryString.Keys.Cast<string>();
                         var expanded = requestKeys.Any(key =>  key.StartsWith("PollsGrid_"));
                         row.DetailRow.Expanded = expanded;
                     }
                 })
 
 
 
 
   // --------------------------- AgendaGrid code starts again ------------------------------------------------
 
            
           //.DataBinding(dataBinding =>
           //     {
           //         dataBinding.Server()
           //             .Select("EditSpeaker", "Speakers", new { micrositeId = worky.MicrositeId })
           //             .Insert("InsertSpeaker", "Speakers", new { micrositeId = worky.MicrositeId })
           //             .Delete("DeleteSpeaker", "Speakers", new { micrositeId = worky.MicrositeId })
           //             .Update("UpdateSpeaker", "Speakers", new { micrositeId = worky.MicrositeId });
 
           //     })
           .Columns(columns =>
           {
 
               columns.Bound(e => e.AgendaPointID).Width(105).ReadOnly();
               columns.Bound(e => e.AgendaPointTitle).Width(130).Encoded(false);
 
               //columns.Command(commands =>
               //{
               //    commands.Edit();
               //    commands.Delete();
               //}).Width(50);
 
           })
           .Sortable()
           .Filterable()
           .Pageable()
           .Resizable(resize => resize.Columns(true))
           .DataKeys(keys => { keys.Add(e => e.AgendaPointID)
               .RouteKey("AgendaId"); })
           .Render(); %>



I am wanting to insert a new Item in a details view inside another details View (which would be my PollsQuestion DetailsView Grid). It seems that when I run my code I get the error:

Exception Details: System.ArgumentException "The key with the following name "NoRecords" was not found. Please update all localization files."

Which points to my PollQuestionsGrid details view.

But if I put an if (x.Poll.PollQuestions.Count() != 0) around this grid then I get no grid which stops me from adding a new PollQuestion.

Hope thats enough info
Thx

2 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 13 Oct 2010, 11:21 AM
I found what the problem was:
I recently updated telerik mvc version and forgot to update my Editor and GridLocalization files in my App_GlobalResources folder.

Thx
0
Tord
Top achievements
Rank 1
answered on 26 Nov 2010, 10:39 AM
Thank you Matthew, you saved me a lot of time. :)

I had translated the grid localization strings to my native language. Some new strings have been added to the resource files in the new release. (Which of course were missing from my translated file). Adding the missing strings fixed this problem for me.
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Tord
Top achievements
Rank 1
Share this question
or