SharePoint - How to sort xmldatasource dropdownlist values in infopath programatically?

Asked By Muthu Kumar on 13-Jun-12 04:38 AM
Hi All,

I have loaded the dropdown values using XMLDataSource in infopath 2007. I need the code to sort the dropdown values by ascending order... Any Ideas?...

Thanks & Regards,
Muthukumar.G
kalpana aparnathi replied to Muthu Kumar on 13-Jun-12 05:10 AM
hi,

Try below code:

Dim xpnRootNode As XPathNavigator = nav.SelectSingleNode("/my:myFields", NamespaceManager)
Dim xpnDataGroup As XPathNavigator = nav.SelectSingleNode("//my:myFields/my:Vendor", NamespaceManager)
Dim xpnTemplate As XPathNavigator = xpnDataGroup.Clone()
For i As Integer = 0 To (count - 1) 'This loops through my array with data to display. my array name is called arrayList
Dim xpnNewData As XPathNavigator = xpnTemplate.Clone()
xpnNewData.SelectSingleNode("/my:myFields/my:Vendor/my:ddlVendorName1", NamespaceManager).SetValue(arrayList(i))
xpnDataGroup.InsertAfter(xpnNewData)
Next
xpnDataGroup.DeleteSelf()


Regards,
Muthu Kumar replied to kalpana aparnathi on 14-Jun-12 04:32 AM
Thanks... I will try...
Jitendra Faye replied to Muthu Kumar on 15-Jun-12 01:24 AM
TRy like this-

ArrayList arrList = new ArrayList();

      //Adding all items of DropDownList to ArrayList
      foreach (ListItem item in drpNames.Items)
      {
        arrList.Add(item.Text);
      }

      //Sorting ArrayList using Sort() method
      arrList.Sort();

      //Clearing all previous items of DropDownList
      drpNames.Items.Clear();

      //Filling DropDownList with sorted items
      foreach (string item in arrList)
      {
        drpNames.Items.Add(item);
      }

Try this and let me know.