Dropdownlist loaded by XML file in ASP.NET 3.5


/ Published in: ASP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. '//////////////////
  2. '/ The DropDownList
  3. '//////////////
  4.  
  5. <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="ddlText" DataValueField="ddlValue" />
  6.  
  7. '//////////////////
  8. '/ The Xml
  9. '//////////////
  10.  
  11. <?xml version="1.0" encoding="utf-8" ?>
  12.  
  13. <Items>
  14. <Item ddlValue ="1" ddlText="YourlistItem1" />
  15.  
  16. <Item ddlValue ="2" ddlText="YourlistItem2" />
  17. <Item ddlValue ="3" ddlText="YourlistItem3" />
  18.  
  19. </Items>
  20.  
  21. '//////////////////
  22. '/ VB Code Behind
  23. '//////////////
  24.  
  25. Imports System.Xml
  26. Imports System.Data
  27.  
  28. LoadDropDownList(ddlist As object)
  29. Dim ddlDataSource As New DataSet
  30. ddlDataSource.ReadXml(MapPath("XmlFile.xml"))
  31. ddlist.DataSource = ddlDataSource
  32. ddlist.DataBind()
  33. End Sub

URL: http://forums.asp.net/p/999571/1327181.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.