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

RadGrid Insert Item when Empty Grid

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aleksander
Top achievements
Rank 1
Aleksander asked on 13 Mar 2012, 09:44 PM
So I'm using a radgrid tied to an object data source see grid code below...

<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?

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Mar 2012, 09:21 AM
Hello Aleksander,


<InsertItemTemplate>
                                    <tk:RadTextBox ID="tbAdminEmails" runat="server" Text='<%# Bind("AdminEmails") %>' TextMode="MultiLine" Width="500px" Height="100px" MaxLength="2000" />
                                </InsertItemTemplate>

Please remove below code part.

Text='<%# Bind("AdminEmails") %>'

If you want to assign this value on insert mode then assign it using ItemDataBound event.

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Aleksander
Top achievements
Rank 1
answered on 14 Mar 2012, 04:28 PM
I have changed the code to...

<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" 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="" 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="" 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="" 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" />


and i still get Error: Sys.WebForms.PageRequestManagerServerErrorException: DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'ThresholdName'.
0
Tsvetina
Telerik team
answered on 19 Mar 2012, 10:01 AM
Hello Aleksander,

You could try setting a default insert value for the column in question. Use the DefaultInsertValue property of the GridTemplateColumn or do this manually in ItemCommand (when the command name is InitInsert).
For more information you could check out this help article on know reasons for error messages in RadGrid;
http://www.telerik.com/help/aspnet-ajax/grid-error-messages.html

All the best,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Aleksander
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Aleksander
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or