So I'm using a radgrid tied to an object data source see grid code below...
The problem is it works great if at least one record exists but if I have a collection of object with count = 0 (no records) and I click the add new record button i get a:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'ThresholdName'.
What am I doing wrong?
<tk:RadGrid ID="rgThreshold" runat="server" AllowPaging="True" Width="100%" PageSize="10" Skin="Black" OnInsertCommand="rgThreshold_InsertCommand" OnDeleteCommand="rgThreshold_DeleteCommand" OnUpdateCommand="rgThreshold_UpdateCommand" AutoGenerateColumns="False" AllowSorting="True" CellSpacing="0" OnNeedDataSource="rgThreshold_NeedDataSource" > <PagerStyle Mode="NextPrevAndNumeric" /> <ValidationSettings EnableValidation="true" EnableModelValidation="true" CommandsToValidate="Insert,Edit" /> <MasterTableView CommandItemDisplay="Top" EditMode="EditForms" InsertItemDisplay="Top" AutoGenerateColumns="false" DataKeyNames="ThresholdID" EditFormSettings-EditColumn-ButtonType="ImageButton"> <CommandItemSettings AddNewRecordText="Add New Threshold" /> <Columns> <tk:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"> <ItemStyle CssClass="myImageButton" /> </tk:GridEditCommandColumn> <tk:GridBoundColumn HeaderText="Threshold ID" DataField="ThresholdID" Display="false" UniqueName="ThresholdID" ReadOnly="true" /> <tk:GridTemplateColumn HeaderText="Threshold Number" DataField="ThresholdNumber" UniqueName="ThresholdNumber" SortExpression="ThresholdNumber" ColumnEditorID="ThresholdNumberEditor" HeaderStyle-Width="150px" > <ItemTemplate> <%# Eval("ThresholdNumber") %> </ItemTemplate> <InsertItemTemplate> <tk:RadNumericTextBox ID="tbThresholdNumber" runat="server" Value="5" DbValue='<%# Bind("ThresholdNumber") %>' Width="50px" ShowSpinButtons="true" NumberFormat-DecimalDigits="0" /> <asp:RequiredFieldValidator ID="rfvThresholdNumber" runat="server" ControlToValidate="tbThresholdNumber" Text="Threshold Number is Required." InitialValue="" Display="Dynamic" CssClass="Validator" /> </InsertItemTemplate> <EditItemTemplate> <tk:RadNumericTextBox ID="tbThresholdNumber" runat="server" DbValue='<%# Bind("ThresholdNumber") %>' Width="50px" ShowSpinButtons="true" NumberFormat-DecimalDigits="0" /> <asp:RequiredFieldValidator ID="rfvThresholdNumber" runat="server" ControlToValidate="tbThresholdNumber" Text="Threshold Number is Required." InitialValue="" Display="Dynamic" CssClass="Validator" /> </EditItemTemplate> </tk:GridTemplateColumn> <tk:GridTemplateColumn HeaderText="Threshold Name" DataField="ThresholdName" UniqueName="ThresholdName" ColumnEditorID="ThresholdNameEditor" HeaderStyle-Width="300px"> <ItemTemplate> <%# Eval("ThresholdName") %> </ItemTemplate> <InsertItemTemplate> <tk:RadTextBox ID="tbThresholdName" runat="server" Text='<%# Bind("ThresholdName") %>' Width="500px" MaxLength="100" /> <asp:RequiredFieldValidator ID="rfvThresholdName" runat="server" ControlToValidate="tbThresholdName" Text="Threshold Name is Required." InitialValue="" Display="Dynamic" CssClass="Validator" /> </InsertItemTemplate> <EditItemTemplate> <tk:RadTextBox ID="tbThresholdName" runat="server" Text='<%# Bind("ThresholdName") %>' Width="500px" MaxLength="100" /> <asp:RequiredFieldValidator ID="rfvThresholdName" runat="server" ControlToValidate="tbThresholdName" Text="Threshold Name is Required." InitialValue="" Display="Dynamic" CssClass="Validator" /> </EditItemTemplate> </tk:GridTemplateColumn> <tk:GridTemplateColumn HeaderText="Emails" DataField="Emails" UniqueName="Emails" ColumnEditorID="EmailsEditor" HeaderStyle-Width="400px"> <ItemTemplate> <%# Eval("Emails") %> </ItemTemplate> <InsertItemTemplate> <tk:RadTextBox ID="tbEmails" runat="server" Text='<%# Bind("Emails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" /> <asp:RequiredFieldValidator ID="rfvEmails" runat="server" ControlToValidate="tbEmails" Text="Emails are Required." InitialValue="" Display="Dynamic" CssClass="Validator" /> </InsertItemTemplate> <EditItemTemplate> <tk:RadTextBox ID="tbEmails" runat="server" Text='<%# Bind("Emails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" /> <asp:RequiredFieldValidator ID="rfvEmails" runat="server" ControlToValidate="tbEmails" Text="Emails are Required." InitialValue="" Display="Dynamic" CssClass="Validator" /> </EditItemTemplate> </tk:GridTemplateColumn> <tk:GridTemplateColumn HeaderText="CC Emails" DataField="AdminEmails" UniqueName="AdminEmails" ColumnEditorID="AdminEmailsEditor" HeaderStyle-Width="400px"> <ItemTemplate> <%# Eval("AdminEmails") %> </ItemTemplate> <InsertItemTemplate> <tk:RadTextBox ID="tbAdminEmails" runat="server" Text='<%# Bind("AdminEmails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" /> </InsertItemTemplate> <EditItemTemplate> <tk:RadTextBox ID="tbAdminEmails" runat="server" Text='<%# Bind("AdminEmails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" /> </EditItemTemplate> </tk:GridTemplateColumn> <tk:GridButtonColumn ConfirmText="Delete this Threshold (All Assignments will also be deleted)?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete Threshold" CommandArgument="ThresholdID" CommandName="Delete" ConfirmDialogHeight="100px" ConfirmDialogWidth="220px" ButtonType="ImageButton" /> </Columns> <EditFormSettings ColumnNumber="2" CaptionDataField="ThresholdName" CaptionFormatString="Edit: {0}"> <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> </EditFormSettings> </MasterTableView> </tk:RadGrid> <tk:RadWindowManager ID="RadWindowManager1" runat="server" Skin="Black" /> <tk:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Black" />The problem is it works great if at least one record exists but if I have a collection of object with count = 0 (no records) and I click the add new record button i get a:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'ThresholdName'.
What am I doing wrong?