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

Editing a record in a details table for grid bound to xml file

2 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
marcos
Top achievements
Rank 1
marcos asked on 26 May 2009, 05:24 PM
Hello, I have a grid bound to an xml file and I am using a GridEditCommandColumn to edit the record. But when I click this button, I am getting a js error "Problem extracting DataKeyValues from DataSource" and I do not see the edit form. The edit works for the MasterTableView, but not on the DetailTable.

Below is my grid followed by how I populate the second level details table:

<telerik:RadGrid ID="RadGrid1" DataSourceID="XmlDataSource1" runat="server" ShowStatusBar="true" 
            AutoGenerateColumns="False" PageSize="3" AllowSorting="True" AllowMultiRowSelection="False" 
            AllowPaging="True" GridLines="None" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" 
            AllowAutomaticUpdates="True" OnItemUpdated="RadGrid1_ItemUpdated" 
            OnInsertCommand="RadGrid1_InsertCommand" OnItemCommand="RadGrid1_ItemCommand"
            <PagerStyle Mode="NumericPages"></PagerStyle> 
            <MasterTableView DataSourceID="XmlDataSource1" DataKeyNames="ServerID" AllowMultiColumnSorting="True" 
                Width="100%" CommandItemDisplay="Top" Name="Servers" AutoGenerateColumns="false"
                <DetailTables> 
                    <telerik:GridTableView DataKeyNames="SystemID" DataSourceID="XmlDataSource2" Width="100%" 
                        runat="server"  CommandItemDisplay="Top" Name="Systems" AutoGenerateColumns="false"
                         
                        <Columns> 
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn2"
                                <HeaderStyle Width="20px" /> 
                                <ItemStyle CssClass="MyImageButton" /> 
                            </telerik:GridEditCommandColumn> 
                            
                            <telerik:GridBoundColumn SortExpression="LoginUrl" HeaderText="Login URL" HeaderButtonType="TextButton" 
                                DataField="LoginUrl" UniqueName="LoginUrl"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn SortExpression="LogoutUrl" HeaderText="LogoutUrl" 
                                HeaderButtonType="TextButton" DataField="LogoutUrl" UniqueName="LogoutUrl"
                            </telerik:GridBoundColumn> 
                             
                        </Columns> 
                        
                    </telerik:GridTableView> 
                </DetailTables> 
                <Columns> 
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                        <HeaderStyle Width="20px" /> 
                        <ItemStyle CssClass="MyImageButton" /> 
                    </telerik:GridEditCommandColumn> 
                    <telerik:GridBoundColumn SortExpression="ServerID" HeaderText="ServerID" HeaderButtonType="TextButton" 
                        DataField="ServerID" UniqueName="ServerID" ReadOnly="true"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="Name" HeaderText="Name" HeaderButtonType="TextButton" 
                        DataField="Name" UniqueName="Name"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn SortExpression="Group" HeaderText="Group" HeaderButtonType="TextButton" 
                        DataField="Group" UniqueName="Group"
                    </telerik:GridBoundColumn> 
                    
                </Columns> 
                
            </MasterTableView> 
        </telerik:RadGrid> 

how i populate the second level grid:

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
        { 
            if (e.CommandName == RadGrid.ExpandCollapseCommandName ) 
            { 
                XmlDataSource2.XPath = String.Format("Servers/Server[@ServerID='{0}']/System", ((GridDataItem)e.Item).GetDataKeyValue("ServerID")); 
            } 
        } 

Any help would be appreciated.
Thanks





2 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 27 May 2009, 08:33 AM

Hello marcos,

Can you please verify that you have SystemID values in the xml file used by XmlDataSource2? If the SystemID values are defined in the same way as those for the master table, there should not be a problem extracting them.

Additionally, check whether defining the XPath property for XmlDataSource2 inside the DetailTableDataBind handler of the grid produces different result.

Kind regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
marcos
Top achievements
Rank 1
answered on 28 May 2009, 03:30 PM
Thanks for the reply. I added the following, and it is now working. Both the master and detail view are usign the same xml file, so the SystemID was not the issue.

protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) 
        { 
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; 
            switch (e.DetailTableView.Name) 
            { 
                case "Systems"
                    { 
                        string CustomerID = dataItem.GetDataKeyValue("ServerID").ToString(); 
                        XmlDataSource2.XPath = String.Format("Servers/Server[@ServerID='{0}']/System", dataItem.GetDataKeyValue("ServerID")); 
         
                        break
                    } 
 
            } 
        } 

Tags
Grid
Asked by
marcos
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
marcos
Top achievements
Rank 1
Share this question
or