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

asp Datasource: Inline XML

3 Answers 114 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 13 Feb 2019, 09:18 PM

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.

 

 

3 Answers, 1 is accepted

Sort by
0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 14 Feb 2019, 09:05 PM
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.
0
David
Top achievements
Rank 1
answered on 20 Feb 2019, 04:38 PM
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?
0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 20 Feb 2019, 08:36 PM
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.
Tags
DropDownList
Asked by
David
Top achievements
Rank 1
Answers by
Eric R | Senior Technical Support Engineer
Telerik team
David
Top achievements
Rank 1
Share this question
or