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

[Solved] Adding a new row to a RadGrid with NestedView

3 Answers 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joachim
Top achievements
Rank 1
Joachim asked on 29 May 2009, 12:59 PM
Hello team,

I've got a RadGrid containing a NestedViewTemplate with a FormView to modify data in every row.
I need to add a Row to the Radgrid, the row should be expanded and the contained FormView should be in insert mode to add a new entry. How can I do this?

Have a look at my current approach:

<telerik:RadGrid ID="RadGrid1" Skin="WebBlue" runat="server" DataSourceID="dsSelectDirectoryScan"
        GridLines="None" OnItemCommand="RadGrid1_ItemCommand" OnPageIndexChanged="RadGrid1_PageIndexChanged">
        <HeaderContextMenu>
            <CollapseAnimation Duration="200" Type="OutQuint" />
        </HeaderContextMenu>
        <MasterTableView AutoGenerateColumns="False" DataSourceID="dsSelectDirectoryScan" DataKeyNames="DirectoryID">
            <Columns>
                <telerik:GridBoundColumn DataField="SenderCompany" HeaderText="SenderCompany" ReadOnly="True"
                    SortExpression="SenderCompany" UniqueName="SenderCompany">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="SenderName" HeaderText="SenderName" ReadOnly="True"
                    SortExpression="SenderName" UniqueName="SenderName">
                </telerik:GridBoundColumn>
                
                <telerik:GridBoundColumn DataField="ReceiverCompany" HeaderText="ReceiverCompany"
                    ReadOnly="True" SortExpression="ReceiverCompany" UniqueName="ReceiverCompany">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ReceiverName" HeaderText="ReceiverName" ReadOnly="True"
                    SortExpression="ReceiverName" UniqueName="ReceiverName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ScanPath" HeaderText="ScanPath" SortExpression="ScanPath"
                    UniqueName="ScanPath">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="TransferType" HeaderText="TransferType" SortExpression="TransferType"
                    UniqueName="TransferType">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PackageType" HeaderText="PackageType" SortExpression="PackageType"
                    UniqueName="PackageType">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Mode" HeaderText="Mode" SortExpression="Mode"
                    UniqueName="Mode">
                </telerik:GridBoundColumn>
            </Columns>
            <NestedViewTemplate>
            <asp:FormView runat="server" ID="fvDirectoryScanDetails" DataSource="dsDirectoryScanDetails" >
              <ItemTemplate>
                    <asp:TextBox runat="server" ID="txtTest" Text="This is a cool test"></asp:TextBox>
              </ItemTemplate>
              <EditItemTemplate>
                    <asp:TextBox runat="server" ID="txtTest" Text="This is a cool test"></asp:TextBox>
              </EditItemTemplate>
              <InsertItemTemplate>
                    <asp:TextBox runat="server" ID="txtTest" Text="This is a cool test"></asp:TextBox>
              </InsertItemTemplate>
            </asp:FormView>--%>
            <asp:FormView ID="fvDirectoryScanDetails" DataKeyNames="DirectoryID" runat="server" DataSourceID="dsDirectoryScanDetails" OnDataBound="fvDirectoryScanDetails_DataBound" OnItemUpdating="fvDirectoryScanDetails_ItemUpdating" OnItemUpdated="fvDirectoryScanDetails_ItemUpdated" OnItemInserted="fvDirectoryScanDetails_ItemUpdated">
            <EditItemTemplate>              
                       ...many things here...                   
            </EditItemTemplate>
            <InsertItemTemplate>
                ...many things here...
            </InsertItemTemplate>
            <ItemTemplate>
                              ...many things here...
            </ItemTemplate>
        </asp:FormView>
            
            </NestedViewTemplate>
            <ExpandCollapseColumn Visible="True">
            </ExpandCollapseColumn>
        </MasterTableView>
        <FilterMenu>
            <CollapseAnimation Duration="200" Type="OutQuint" />
        </FilterMenu>
    </telerik:RadGrid>

Thanks,

Joachim

3 Answers, 1 is accepted

Sort by
0
Joachim
Top achievements
Rank 1
answered on 29 May 2009, 01:26 PM
Need to add that inserting the new item should be done when clicking a button outside the whole radgrid.
0
Accepted
Peter
Top achievements
Rank 1
answered on 01 Jun 2009, 12:44 PM
Hi,

Your scenario is interesting, but I do not believe that it is achievable to put RadGrid in insert mode and in the same moment to have expanded NestedVeiw with the FromView control.
Why don't you try to use a user control for insert mode. Thus you still will have the ability to edit with the FormView placed in the NestedTemplate. Here is an online demo which uses the user control for editing. You will need also and this code snippet to put the grid in insert mode:
    protected void Button5_Click(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.IsItemInserted = true
        RadGrid1.Rebind(); 
    } 

Regards,
Petar
0
Joachim
Top achievements
Rank 1
answered on 16 Jun 2009, 12:27 PM
Hello Petar,

thank you for your answer. The custom control would most likely solve this issue. However, I had to finish the matter quickly before I went on holidays for the last two weeks.

What I did is to add another FormView beneath the RadGrid to add new entries directly. This is a little change in direction from what I planned first, but is sufficient at the moment.

Regards,

Joachim
Tags
Grid
Asked by
Joachim
Top achievements
Rank 1
Answers by
Joachim
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Share this question
or