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

Populate a Hierarchy RadGrid with XML

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Emmanuel
Top achievements
Rank 1
Emmanuel asked on 27 Jan 2011, 11:49 AM
Hello everybody,

I have a problem : I hava an XML File like this one :
<?xml version="1.0" encoding="utf-8" ?>
<Catalog>
    <Family Name="Family1">
        <SubFamily Name="List1">
            <Product Name="Product1" Packaging="5"></Product>
            <Product Name="Product2" Packaging="5"></Product>
            <Product Name="Product3" Packaging="25" ></Product>
        </SubFamily>
        <SubFamily Name="List2">
            <Product Name="Product1" Packaging="25"></Product>
        </SubFamily>
    </Family>
    <Family Name="Family2">
        <SubFamily Name="List1">
            <Product Name="Product1" Packaging="10"></Product>
            <Product Name="Product2" Packaging="10"></Product>
        </SubFamily>
        <SubFamily Name="List2">
            <Product Name="Product1" Packaging="10"></Product>
        </SubFamily>
    </Family>
</Catalog>

What I want is to obtain a RadGrid constructed with the same hierarchy.

The code I use now is :
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Web20" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateHierarchy="True" >
    <MasterTableView HierarchyDefaultExpanded="True">
        <Columns>                
        </Columns>       
    </MasterTableView>
</telerik:RadGrid>
public void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        RadGrid1.DataSource = GetHierarchicalXmlData();
    }
 
    private DataSet XMLDataSet;
    private DataSet GetHierarchicalXmlData()
    {
        XMLDataSet = new DataSet();
        XmlTextReader reader = new XmlTextReader(myfilename); // myfilename is the fullpath for the xml file
        XMLDataSet.ReadXml(reader);
       
        return XMLDataSet;
    }

The problem is that the hierarchy is well respected (see the picture in attached files) BUT RadGrid add "IDs" columns automatically...

1) What can I do to hide these ID Columns that are not presents in my XML File ?
2) Can I add an empty textbox for each Product Row in the end of each line ? How ?

Thanks a lot for your help :) 



1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 01 Feb 2011, 02:46 PM
Hi Emmanuel,

1. To hide any of the auto-generated columns, you can handle the ColumnCreated event and set the Visible property for the currently created column to false.
2. You can use the last column to add the TextBox there. You can do that by handling the ItemCreated and ItemDataBound events and place the same code for adding the textBox at both places.

Best wishes,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Emmanuel
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or