asp Datasource: Inline XML

4 posts, 0 answers
  1. David
    David avatar
    41 posts
    Member since:
    Aug 2014

    Posted 13 Feb Link to this post

    Attempting to use an XmlDataSource to populate the values in a dropdown list control in a GridTemplateColumn edit and insert templates.

    Searched over:
     1 - using ASP datasources: https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/data-binding/binding-to-asp-datasource-components
     2 - using inline XML in an XmlDataSource: http://www.java2s.com/Code/ASP/XML/UsingInlineXMLDatainanXmlDataSourceControl.htm
     3 - fixing the 'GridInsertionObject does not contain a property named 'X' ' error: https://weblogs.asp.net/kencox/fixing-the-telerik-webcontrols-gridinsertionobject-does-not-contain-a-property-error
     4- Populating a dropdownlist in a datagrid template column: https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/how-to/Common/radcombobox-in-radgrid
     
     * Yes, the links above reference the combobox control, presumably the dropdown list functions the same way.
     
     Goal: Populate a DropDown list using an XmlDataSource and inline XML
     
     Problem: it does not work.
     Looking for the proper format of the inline XML to get this to work.
      Links 1 and 4 say that the XML file has to be formatted as <items><item>, but this causes an error when inline stating that 'items' is invalid'
      Links 2 say to use <Data><items><item>, which doesn't throw an error but doesn't load
      Using the method from Link 3 to set the default values, I avoid the GridInsertObject error, but the defaulted value is not bound.

    <telerik:GridTemplateColumn HeaderText="Wpn Qual" DefaultInsertValue="M">
        <ItemTemplate><%#DataBinder.Eval(Container.DataItem,"WPN_QUAL_BADGE") %></ItemTemplate>
        <EditItemTemplate>
            <telerik:RadDropDownList runat="server" ID="ddlWpnQual" DataTextField="Text" DataValueField="Value" DataSourceID="xmlWpnQual"
                SelectedValue='<%#Bind("WPN_QUAL_BADGE") %>' ></telerik:RadDropDownList>
        </EditItemTemplate>
        <InsertItemTemplate>
            <telerik:RadDropDownList runat="server" ID="ddlWpnQual" DataTextField="Text" DataValueField="Value" DataSourceID="xmlWpnQual"
                SelectedValue='<%#Bind("WPN_QUAL_BADGE") %>' ></telerik:RadDropDownList>
        </InsertItemTemplate>
    </telerik:GridTemplateColumn>

     

    <asp:XmlDataSource ID="xmlWpnQual" runat="server" XPath="Data/Items" >
        <Data>
            <Items>
                <Item Text="-- Select --" Value="" />
                <Item Text="Marksman" Value="M" />
                <Item Text="SharpShooter" Value="S" />
                <Item Text="Expert" Value="E" />
            </Items>
        </Data>
    </asp:XmlDataSource>

     

    And yes, I can manually create the items via markup in each instance of the dropdownlist... I would prefer to use a scalable approach in this specific instance.

     

     

  2. Eric
    Admin
    Eric avatar
    10 posts

    Posted 14 Feb Link to this post

    Hi David,

    Thank you for sending over your source code. I was able to replicate the scenario and found that if you remove the XPath from the XmlDataSource the values load correctly. Please see the below markup that I used.


    ASP.NET WebForm

    <div>
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" PageSize="30" ShowGroupPanel="True" Skin="Metro" Width="900px" OnNeedDataSource="RadGrid1_NeedDataSource">
            <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
            <ClientSettings AllowDragToGroup="True">
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            </ClientSettings>
            <MasterTableView AllowFilteringByColumn="False" AutoGenerateColumns="False" DataKeyNames="CustomerID">
                <Columns>
                    <telerik:GridBoundColumn DataField="CustomerID" FilterControlAltText="Filter CustomerID column" HeaderText="Customer ID" ReadOnly="True" SortExpression="CustomerID" UniqueName="CustomerID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CompanyName" FilterControlAltText="Filter CompanyName column" HeaderText="Company Name" SortExpression="CompanyName" UniqueName="CompanyName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ContactName" FilterControlAltText="Filter ContactName column" HeaderText="Contact Name" SortExpression="ContactName" UniqueName="ContactName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Country" FilterControlAltText="Filter Country column" HeaderText="Country" SortExpression="Country" UniqueName="Country">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column" HeaderText="TemplateColumn" UniqueName="TemplateColumn">
                        <EditItemTemplate>
                            <telerik:RadDropDownList ID="RadDropDownList1" runat="server" DataValueField="Value" DataTextField="Text" DataSourceID="xmlWpnQual"></telerik:RadDropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <telerik:RadDropDownList ID="RadDropDownList2" runat="server" DataTextField="Text" DataValueField="Value" DataSourceID="xmlWpnQual"></telerik:RadDropDownList>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    <asp:XmlDataSource ID="xmlWpnQual" runat="server">
        <Data>
            <Items>
                <Item Text="-- Select --" Value="" />
                <Item Text="Marksman" Value="M" />
                <Item Text="SharpShooter" Value="S" />
                <Item Text="Expert" Value="E" />
            </Items>               
        </Data>
    </asp:XmlDataSource>


    Please let me know if you have any additional questions and thank you for using the Telerik Forums.


    Regards,

    Eric
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. David
    David avatar
    41 posts
    Member since:
    Aug 2014

    Posted 20 Feb Link to this post

    Thanks! That helps.

    Would the XPath be used if it was structured as <Data><Scores><Items>....

    That way you could use one XML data source and filter at the second level?
  4. Eric
    Admin
    Eric avatar
    10 posts

    Posted 20 Feb Link to this post

    Hi David,

    I am glad it is helpful. The DropDownList documentation recommends a flat Data -> Collection -> Item format.  I tested the following and it works.

    <asp:XmlDataSource ID="xmlWpnQual" runat="server">
        <Data>
                <Scores>
                    <Score Text="-- Select --" Value="" />
                    <Score Text="Marksman" Value="M" />
                    <Score Text="SharpShooter" Value="S" />
                    <Score Text="Expert" Value="E" />
                </Scores>
        </Data>
    </asp:XmlDataSource>

    Regarding XPath

    The Telerik components don't particularly care how deep the data is in the XML, as long as the XPath brings that level up to the surface for consumption by the control. 

    In the case of the RadComboBox, it needs to be flat data as I mentioned above and the example is representative of that flat data structure. If you need to write an XPath expression to raise that nested node to the RadComboBox, you'll need to make sure the structure matches the required data.

    Since the XmlDatasource is an ASP.NET component, we don't have any Telerik documentation on the topic other than this section on XmlDataSource for the TreeView. If you need further assistance on writing an XPath expression, I recommend reviewing Microsoft's documentation on the topic. Here's one page to get started - XPath Examples.

    Let me know if that is what you were looking for and thank you for choosing Progress Telerik.

    Regards,

    Eric
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top