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

Add new record in radgrid

8 Answers 468 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rem
Top achievements
Rank 1
Rem asked on 15 Jan 2014, 01:45 PM
Hi,

I am using add new record property of radgrid. All my columns are adding to new row except gridclientselectcolumn & gridclientdeletecolumn.

Another problem is the gridclientselectcolumn can be viewed as checkbox on focus and displays true/false when focus moves out.

Help me urgently.

8 Answers, 1 is accepted

Sort by
0
Rem
Top achievements
Rank 1
answered on 16 Jan 2014, 05:10 AM
somebody plz help me on this
0
Princy
Top achievements
Rank 2
answered on 16 Jan 2014, 09:02 AM
Hi Rem,

I was not able to replicate the issue, can you try to add the GridClientDeleteColumn and GridClientSelectColumn to the following demo's and check if the issue exists. If this doesn't help, please provide your code snippet:
Grid - Automatic Operations and Grid - Manual CRUD Operations.

Thanks,
Princy

0
Rem
Top achievements
Rank 1
answered on 17 Jan 2014, 11:23 AM
I have a GridclientDeletecolumn in my grid. On adding new record, GridclientDeletecolumn  is generated as empty.
I went through the example given. I copied the same and tried, still issue persistes.
And the itemindexes of the new row generated are -1,-2,-3....
My code is
<telerik:RadGrid ID="gvAllergies" runat="server" GridLines="None" AllowAutomaticDeletes="True"
                        AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" Width="96%"
                        CellSpacing="0" Skin="Outlook">
                        <ClientSettings>
                            <ClientEvents OnRowCreated="RowCreated" />
                        </ClientSettings>
                        <MasterTableView CommandItemDisplay="Bottom" CommandItemSettings-AddNewRecordText=""
                            CommandItemSettings-CancelChangesText="" InsertItemDisplay="Bottom" HorizontalAlign="NotSet"
                            EditMode="Batch" AutoGenerateColumns="False" ItemStyle-Height="25px" CommandItemSettings-ShowSaveChangesButton="false"
                            CommandItemSettings-ShowRefreshButton="false">
                            <CommandItemSettings AddNewRecordText="" ShowAddNewRecordButton="true" CancelChangesText=""
                                ShowCancelChangesButton="true" />
                            <Columns>
                                <telerik:GridBoundColumn FilterControlAltText="Filter No column" UniqueName="No"
                                    HeaderText="No." DataField="ID" ReadOnly="true">
                                    <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle HorizontalAlign="Center" />
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn FilterControlAltText="Filter Allergen column" UniqueName="Allergen"
                                    HeaderText="Allergen">
                                    <ItemStyle HorizontalAlign="Center" Width="30px" />
                                    <HeaderStyle HorizontalAlign="Center" Width="30px" />
                                    <ItemTemplate>
                                        <asp:Label ID="lblAllergen" runat="server"></asp:Label>
                                    </ItemTemplate>
                                    <InsertItemTemplate>
                                        <telerik:RadComboBox ID="cmbAllergen" runat="server" AutoPostBack="false" DataValueField="ID"
                                            AllowCustomText="true" EnableLoadOnDemand="true" DataTextField="Name" OnItemDataBound="cmbAllergen_ItemDataBound"
                                            OnItemsRequested="cmbAllergen_ItemsRequested" Width="200px" DropDownWidth="350px"
                                            Height="400px" HighlightTemplatedItems="true" OnClientSelectedIndexChanged="ClientSelectedIndexChanged">
                                            <HeaderTemplate>
                                                <table>
                                                    <tr>
                                                        <td style="width: 50px" align="center">
                                                            Code
                                                        </td>
                                                        <td align="center">
                                                            Allergen
                                                        </td>
                                                    </tr>
                                                </table>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <table>
                                                    <tr>
                                                        <td id="cellCode" runat="server" style="width: 50px">
                                                        </td>
                                                        <td id="cellName" runat="server" align="left">
                                                        </td>
                                                    </tr>
                                                </table>
                                            </ItemTemplate>
                                        </telerik:RadComboBox>
                                    </InsertItemTemplate>
                                    <ItemStyle HorizontalAlign="Center" Width="220px" />
                                    <HeaderStyle HorizontalAlign="Center" Width="220px" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn FilterControlAltText="Filter IsChronic column" UniqueName="IsChronic"
                                    HeaderText="IsChronic">
                                    <ItemStyle HorizontalAlign="Left" />
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemTemplate>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn FilterControlAltText="Filter HiddenCheckboxVal column"
                                    UniqueName="HiddenCheckboxVal" Display="false">
                                 </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn FilterControlAltText="Filter Delete column" HeaderText="Delete"
                                    UniqueName="Delete">
                                    <ItemTemplate>
                                    </ItemTemplate>
                                    <HeaderStyle HorizontalAlign="Center" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridBoundColumn FilterControlAltText="Filter HiddenAllergen column" UniqueName="HiddenAllergen"
                                    Display="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridClientDeleteColumn UniqueName="del" HeaderText="Del"></telerik:GridClientDeleteColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
0
Princy
Top achievements
Rank 2
answered on 18 Jan 2014, 04:22 AM
Hi Rem,

I guess you are using Automatic CRUD operation with batch, but i see that you haven't added  AllowAutomaticInserts="true". Add this to your code for your insert to work properly. Then I don't know how you are saving the Grid since you have hidden the Save button. The Delete Column will be added ones the new row is inserted and saved. Here is a sample code that i tried:

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="true"
    AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" Skin="Outlook"
    DataSourceID="SqlDataSource1">
    <MasterTableView CommandItemDisplay="Bottom" DataKeyNames="OrderID" InsertItemDisplay="Bottom"
        EditMode="Batch" AutoGenerateColumns="False" CommandItemSettings-ShowSaveChangesButton="true"
        CommandItemSettings-ShowRefreshButton="false">
        <Columns>
            <telerik:GridBoundColumn FilterControlAltText="Filter OrderID column" UniqueName="OrderID"
                HeaderText="OrderID" DataField="OrderID" ReadOnly="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter ShipName column" UniqueName="ShipName"
                HeaderText="ShipName" DataField="ShipName" ReadOnly="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn FilterControlAltText="Filter ShipVia column" UniqueName="ShipVia"
                HeaderText="ShipVia" DataField="ShipVia">
            </telerik:GridBoundColumn>
            <telerik:GridClientDeleteColumn UniqueName="delete" HeaderText="Delete">
            </telerik:GridClientDeleteColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>"
    DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @OrderID" InsertCommand="INSERT INTO [Orders] ([OrderID], [ShipName], [ShipVia]) VALUES (@OrderID, @ShipName, @ShipVia)"
    SelectCommand="SELECT [OrderID], [ShipName],[ShipVia] FROM [Orders] " UpdateCommand="UPDATE [Orders] SET [ShipName] = @ShipName, [ShipVia] = @ShipVia WHERE [OrderID] = @OrderID">
    <DeleteParameters>
        <asp:Parameter Name="OrderID" Type="Int32"></asp:Parameter>
    </DeleteParameters>
    <InsertParameters>
        <asp:Parameter Name="OrderID" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="ShipName" Type="String"></asp:Parameter>
        <asp:Parameter Name="ShipVia" Type="Int16"></asp:Parameter>
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="OrderID" Type="Int32"></asp:Parameter>
        <asp:Parameter Name="ShipName" Type="String"></asp:Parameter>
        <asp:Parameter Name="ShipVia" Type="Int16"></asp:Parameter>
    </UpdateParameters>
</asp:SqlDataSource>

Thanks,
Princy
0
Rem
Top achievements
Rank 1
answered on 20 Jan 2014, 05:03 AM
Hi Princy,

Thanks for your reply.

I am not using Sqldatasource and I have 7-10 grids in a single page.
And I am trying to save all these from a single button outside. I have to save all these grids together not at the time each row generation.
0
Princy
Top achievements
Rank 2
answered on 20 Jan 2014, 06:20 AM
Hi Rem,

If you want to trigger the saving of the changes from an outer button. This can be achieved by obtaining a reference to the batch editing manager of the grid and calling saveChanges. Please go through this post which discuss the same:
http://www.telerik.com/community/forums/aspnet-ajax/grid/batch-editing---need-to-have-the-save-changes-button-outside-the-grid.aspx#2691359

Thanks,
Princy
0
Rem
Top achievements
Rank 1
answered on 20 Jan 2014, 06:37 AM
Hi Princy,

I am trying to save my grid data by invoking BatchEditingManager.

But my issue is all the new rows generated have the indexes 0,-1,-2,-3,..... All are negative values.

Another problem is i have added gridclientdelete column. It can't be reproduced to the new row.

Its urgent, since we have evaluate it and to buy soon.
0
Angel Petrov
Telerik team
answered on 22 Jan 2014, 08:49 AM
Hi Rem,

I am not sure about the exact scenario but I suppose that you are targeting the id of the newly created rows which contain a '-' character. Note however that this is expected behavior is used to determine the insert from edit items. Moreover the negative sign in the id does not reflect the data and you should be able to access it without any problems on the server. On how to achieve this I suggest that you examine this help article.

As for the GridClientDeleteColumn I have to say that the behavior experienced is expected. When the Add new record button is clicked RadGrid will only append a new tr element to it's table. It will not initialize any controls such as buttons, text boxes or etc in it. In order to display a button for the new rows you should manually add one by using JavaScript. Here attached is a sample which demonstrates a possible realization.

Regards,
Angel Petrov
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Rem
Top achievements
Rank 1
Answers by
Rem
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Angel Petrov
Telerik team
Share this question
or