locked
Sort in data XML RRS feed

  • Question

  • User-1031820653 posted

    Hi,

    Need help to sort data which is coming from XML.

    I am displaying some data in Checkbox list which is coming from XML.data is coming fine but i need it in by Sort by Name

    here is my code

    aspx

    <div class="CheckBoxList1">
    <asp:CheckBoxList ID="chkListOrganizations" runat="server" Width="400" CssClass="chkbox"
    DataSourceID="xDsOrgUnits" DataMember="Name" DataValueField="value" DataTextField="Name"
    OnSelectedIndexChanged="chkListOrganizations_SelectedIndexChanged" AutoPostBack="true"
    CausesValidation="true">
    </asp:CheckBoxList>
    <asp:XmlDataSource ID="xDsOrgUnits" runat="server" DataFile="../App_Data/OrgUnit.xml">

    </asp:XmlDataSource>

    C#

    DataRowView drvSender = sender as DataRowView;
    String strReturnValue = String.Empty;
    if (drvSender != null)
    {
    switch (colName)
    {

    //using organization column
    case "Org":
    {
    String orgName = String.Empty;
    //reference to the xml document that contains the organization and sub organization details
    XmlDocument xmlDocOrganizations = xDsOrgUnits.GetXmlDocument();

    //fetch the organization by using the parent node of the selected sub organization in the above xml file
    String xpath = "Elements/NewOrgUnit[./Control[@value='{0}']]";
    xpath = String.Format(xpath, drvSender["SubOrganization"].ToString());

    XmlNodeList xListResults = xmlDocOrganizations.SelectNodes(xpath);
    strReturnValue = xListResults[0].Attributes["Name"].Value;

    break;
    }

    Please help!Thanks In Advance

    Tuesday, September 30, 2014 5:40 AM

Answers

  • User1508394307 posted

    There are 2 ways: 1) sort xml with help of xslt (read this) 2) do not use XmlDataSource and sort/bind data from the code (read this

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 30, 2014 6:22 AM