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

Sub Grid Errors on Insert EditForm if no Existing data

3 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 09 Jun 2014, 08:34 PM
I am having a problem inserting records on a Sub heirarchial grid.  If no dta exists it errors our the bind function for the editing.  But if existing data is loaded for that sub grid the insert works just fine.   So on insert of the datatable has nothing in it it will error out on the 1st textbox that is bound to data from datatable and give the follwoing error.  But the problem is the field is there becuase it works for other rows with data.  If you manually insert record, it will work fine.  What is the work around to this.

DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'strDescription'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.Web.HttpException: DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'strDescription'.


<EditFormSettings EditFormType="Template">
                                               <FormTemplate>
                                                       <table style="width:100%;background-color:antiquewhite">
                                                           <tr>
                                                               <td style="height:10px"></td>
                                                           </tr>
                                                           <tr>
                                                               <td style="width:10%;text-align:right">Position Description: </td>
                                                               <td style="width:90%;text-align:left"><asp:TextBox ID="txtdescription" runat="server" Width="200px" Text='<%#Bind("strDescription") %>'></asp:TextBox></td>
                                                           </tr>
                                                           <tr>
                                                               <td style="height:10px"></td>
                                                           </tr>
                                                           <tr>
                                                               <td style="width:10%;text-align:right">Position Scale: </td>
                                                               <td style="width:90%;text-align:left"><asp:TextBox ID="txtScale" runat="server" Width="200px" Text='<%#Bind("strScale") %>'></asp:TextBox></td>
                                                           </tr>
                                                           <tr>
                                                               <td style="height:10px"></td>
                                                           </tr>
                                                           <tr>
                                                               <td style="width:10%;text-align:right">Position Type: </td>
                                                               <td style="width:90%;text-align:left"><asp:TextBox ID="txtPosType" runat="server" Width="200px" Text='<%#Bind("strPositionType") %>'></asp:TextBox></td>
                                                           </tr>
                                                           <tr>
                                                               <td style="height:10px"></td>
                                                           </tr>
                                                           <tr>
                                                               <td style="width:10%;text-align:right">Position Grade: </td>
                                                               <td style="width:90%;text-align:left"><asp:TextBox ID="txtGrade" runat="server" Width="200px" Text='<%#Bind("strGrade") %>'></asp:TextBox></td>
                                                           </tr>
                                                           <tr>
                                                                   <td style="height:5px"></td>
                                                           </tr>
                                                           <tr>
                                                               <td style="width:10%;text-align:right"></td>
                                                               <td style="width:90%;text-align:left">
                                                                       <asp:LinkButton ID="lnkSubmit" runat="server" Text='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? "Insert" : "Update" %>'
                                                                       CommandName='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? "PerformInsert" : "Update" %>'>
                                                                       </asp:LinkButton>
                                                                            
                                                                       <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                                                               </td>
                                                           </tr>
                                                       </table>
                                               </FormTemplate>
                                        </EditFormSettings>      
 
 
if (e.CommandName == RadGrid.PerformInsertCommandName && e.Item.OwnerTableView.Name == "Positions")
       {
           GridEditableItem item = e.Item as GridEditableItem;
           GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
           //int sectionId = Convert.ToInt32(item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["intSectionId"]);
           int secId = Convert.ToInt32(parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["intSectionId"]);
           TextBox descrip = (TextBox)item.FindControl("txtdescription");
           TextBox scale = (TextBox)item.FindControl("txtScale");
           TextBox posType = (TextBox)item.FindControl("txtPosType");
           TextBox grade = (TextBox)item.FindControl("txtGrade");
 
           sql = "Execute usp_InsertPosition " + secId + ", '" + c.SanitizeString(descrip.Text) + "', '" + c.SanitizeString(scale.Text) + "', '" + c.SanitizeString(posType.Text) + "', '" + c.SanitizeString(grade.Text) + "'";
 
           c.InsertUpdateDelete(sql);
          // myradGrid.Rebind();
       }

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Jun 2014, 07:24 AM
Hi Kevin,

I was not able to replicate this error at my end. Please take a look at this article which discuss about this error.
Known Reasons for Error Messages

Thanks,
Shinu
0
Kevin
Top achievements
Rank 1
answered on 10 Jun 2014, 06:50 PM
HI,

Ok I tried to correct it with the link that you sent but still a no go.  Here is the code I implimented.  But it still gets the same error there is no strDescription, but only when no record exists at that level.  If one exists it works just fine.

if (e.CommandName == RadGrid.InitInsertCommandName && e.Item.OwnerTableView.Name == "Positions")
        {
            System.Collections.Specialized.ListDictionary newValues = new
            System.Collections.Specialized.ListDictionary();
  
            newValues["strDescription"] = string.Empty;
            newValues["strScale"] = string.Empty;
            newValues["strPositionType"] = string.Empty;
            newValues["strGrade"] = string.Empty;
  
            e.Item.OwnerTableView.InsertItem(newValues);
        }
  
  
This is the section of the Grid
  <Columns>
                                            <telerik:GridEditCommandColumn ButtonType="LinkButton" EditText="Edit" />
                                             <telerik:GridBoundColumn DataField="strDescription" HeaderText="POSITION DESCRP" />
                                             <telerik:GridBoundColumn DataField="gsScale" HeaderText="GS-SCALE" />
                                        </Columns>
                                         <EditFormSettings EditFormType="Template">
                                                <FormTemplate>
                                                        <table style="width:100%;background-color:antiquewhite">
                                                            <tr>
                                                                <td style="height:10px"></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="width:10%;text-align:right">Position Description: </td>
                                                                <td style="width:90%;text-align:left"><asp:TextBox ID="txtdescription" runat="server" Width="200px" Text='<%#Bind("strDescription") %>'></asp:TextBox></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="height:10px"></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="width:10%;text-align:right">Position Scale: </td>
                                                                <td style="width:90%;text-align:left"><asp:TextBox ID="txtScale" runat="server" Width="200px" Text='<%#Bind("strScale") %>'></asp:TextBox></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="height:10px"></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="width:10%;text-align:right">Position Type: </td>
                                                                <td style="width:90%;text-align:left"><asp:TextBox ID="txtPosType" runat="server" Width="200px" Text='<%#Bind("strPositionType") %>'></asp:TextBox></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="height:10px"></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="width:10%;text-align:right">Position Grade: </td>
                                                                <td style="width:90%;text-align:left"><asp:TextBox ID="txtGrade" runat="server" Width="200px" Text='<%#Bind("strGrade") %>'></asp:TextBox></td>
                                                            </tr>
                                                            <tr>
                                                                    <td style="height:5px"></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="width:10%;text-align:right"></td>
                                                                <td style="width:90%;text-align:left">
                                                                        <asp:LinkButton ID="lnkSubmit" runat="server" Text='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? "Insert" : "Update" %>'
                                                                        CommandName='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? "PerformInsert" : "Update" %>'>
                                                                        </asp:LinkButton>
                                                                              
                                                                        <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="false" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                </FormTemplate>
                                         </EditFormSettings>       
                        </telerik:GridTableView>













0
Shinu
Top achievements
Rank 2
answered on 11 Jun 2014, 04:04 AM
Hi Kevin,

Unfortunately I couldn't replicate the issue at my end.

Thanks,
Shinu.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kevin
Top achievements
Rank 1
Share this question
or